wordpress-mobile / wordpress-mobile/WordPress-Android

Site Settings: Categories don't load if there are more than 100

Open
#14,282 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

[Pri] Low [Type] Bug Site Management Tag/Category Management
Dominant language
Kotlin
Stars
3.2k
Forks
1.4k
Avg merge
1d 11h
Merged PRs (30d)
69

Description

Expected behavior

Loading the list of categories under Site Settings for sites with a large number of categories should correctly list them.

Actual behavior

device-2021-03-16-105740

It looks like results returned from the API are paginated to 100, but the logic tries to loop through the found value returned by the API response, which is the grand total of categories (> 100 in this case).

This eventually results in a JSON exception Index 100 out of range [0..100) on the 101st iteration (we're not currently logging the exception), and the function returns null as the list of categories.

This is probably a pretty rare occurrence, I doubt many sites have over 100 categories (this occurred for me on a test site that has had hundreds of categories generated from automated tests in the past).

Steps to reproduce the behavior
  1. Select a WPcom site with over 100 categories
  2. Visit My Site -> Settings
  3. Notice that the 'Default category' item doesn't list what the default is
  4. Tap on 'Default category', and notice that the dialog is blank, like the screenshot above
Tested on Pixel 3, Android 11, WPAndroid 16.9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in WordPress/src/main/java/org/wordpress/android/ui/prefs/WPComSiteSettings.java at lines 956-963 and inspect how the category API response is iterated. Reproduce with a site containing more than 100 categories; done means the categories load without a JSON exception and the Default category dialog is populated.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
mobile
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.