Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nullability Annotations to Java Classes] Add Missing Nullability Annotations to Theme Network Client Classes (safe) #2893

Conversation

ParaskP7
Copy link
Contributor

@ParaskP7 ParaskP7 commented Nov 3, 2023

Parent #2798
Accompanying JP/WPAndroid#19529

This PR adds any missing nullability annotation to ThemeRestClient.java, all its related response classes and anything in between (ie. MediaStore). See response classes below:

FYI.1: This change is safe, meaning that there shouldn't be any (major) compile-time changes associated with this change. Having said that, testing is highly recommended since the changes in this PR can affect one or more clients (ie. JP/WPAndroid, WCAndroid, etc)

FYI.2: An analysis on ThemeStore and its usages with our main clients suggests that this store is only being utilizing by JP/WPAndroid. AFAIA WCAndroid is not using that store and as such can be safely ignored from testing.


PS.1: @antonis I added you as the main reviewer, randomly so, since I just wanted someone from the Jetpack/WordPress mobile team to be aware of and sign-off on that change. Feel free to merge this PR directly yourself if you deem so.


Nullability Annotation List (Response):

  1. Add missing n-a to comment wp com theme response fields
  2. Add missing n-a to comment jetpack theme response fields

Nullability Annotation List (Client):

  1. Add missing n-a to fetch starter designs on theme rest client
  2. Add missing n-a to create theme from wpr on theme rest client
  3. Add missing n-a to create theme from jpr on theme rest client
  4. Add missing n-a to theme id with wp suffix on theme rest clt

Nullability Annotation List (Store):

  1. Add missing n-a to fetched current theme pl on theme store
  2. Add missing n-a to fetched site themes payload on theme store
  3. Add missing n-a to fetched wp com themes pl on theme store
  4. Add missing n-a to fetched starter designs pl on theme store

Nullability Checks List:

  1. Un-guard usages of jetpack screenshot url on theme rest client

Warnings Resolutions List:

  1. Make inner classes static on wp com theme response
  2. Make inner classes static on jetpack theme response
  3. Delete unused term id field on wp com theme response

Warnings Suppression List:

  1. Suppress raw types warning on theme store

Refactor List:

  1. Reformat theme rest client
  2. Replace anonymous classes with lambda on theme rest client

Test List:

  1. Add missing final to theme store on theme store test
  2. Resolve robolectric related application deprecation warning
  3. Simplify assert true assertions on theme store test
  4. Suppress new class naming convention for connected tests
  5. Simplify assert true assertion on rs theme test jetpack
  6. Simplify assert true assertions on rs theme test jetpack
  7. Simplify assert false assertion on rs theme test jetpack
  8. Simplify authenticate wp com fetch sites on rs theme test jetpack

Docs List:

  1. Replace url with html link on theme rest client

Demo List:

  1. Add select site functionality to theme screen on example app
  2. Change theme id input type to text on theme screen of example app

Associated Clients

It is highly recommending that this change is being tested on the below associated clients:


To Test (REST):

  • Smoke test the FluxC Example app via the THEME screen. Verify everything is working as expected.
  • In addition to the above, using local-builds.gradle on JP/WPAndroid, smoke test any theme related functionality on both, the WordPress and Jetpack apps, and see if everything is working as expected. For a couple of examples, you can expand and follow the inner and more explicit test steps within:

To Test (XMLRPC):

N/A

1. [JP/WP] Themes Screen [ThemeBrowserActivity.java + ThemeBrowserFragment.kt]

ℹ️ This test applies to both, the Jetpack and WordPress apps.

  • Go to Themes screen, verify it is shown and functioning as expected.
  • For example try scrolling up-and-down and searching for a theme.
  • Check your current theme and tap on the Customize, Details and Support buttons. Verify that everything works as expected.
  • From the themes list, find your current theme on top, click on its menu items and again tap on the Customize, Details and Support buttons. Verify that everything works as expected.
  • From the themes list, find another theme, other than your current one, click on its menu items and again tap on the Details and Support buttons. Verify that everything works as expected.
  • Then, tap on the View and Try & Customize buttons. Verify that everything works as expected.
  • Finally, tap on Activate button. Verify that the selected theme is activated and that everything works as expected.
2. [JP] Site Creation Screens [SiteCreationActivity.kt + HomePagePickerFragment.kt + DesignPreviewFragment.kt]

ℹ️ This test applies to the Jetpack app only.

  • From Choose Site, tap on the + button on top and via the Create WordPress.com site, go to Site Creation screen, verify it is shown and functioning as expected.
  • For example, while on the What's your website about? screen, select a topic from the list of topics (ie. Food).
  • Then, while on the Choose a theme screen, select a theme from the list of themes (per category, ie About).
  • Finally, verify that the Preview screen is shown and functioning as expected.

Merge instructions:

  1. Wait for the accompanying JP/WPAndroid#19529 to be reviewed and approved.
  2. Remove the [PR] Not Ready for Merge label.
  3. Merge this PR.
  4. Follow-up with the merge instructions on the accompanying JP/WPAndroid#19529 client PR.

Warning: "Link specified as plain text"
FYI: 'n-a' stands for 'nullability annotations'.
FYI: 'n-a' stands for 'nullability annotations'.
FYI: 'n-a' stands for 'nullability annotations'.
FYI: 'n-a' stands for 'nullability annotations'.
Warning: "Raw use of parameterized class 'Action'"
FYI: 'n-a' stands for 'nullability annotations'
FYI: 'n-a' stands for 'nullability annotations'
FYI: 'n-a' stands for 'nullability annotations'
FYI: 'n-a' stands for 'nullability annotations'
Warning: "Field 'mThemeStore' may be 'final'"
Warning: "'application' is deprecated"

Explanation: Accessing this field directly is inherently incompatible
with 'org.robolectric.annotation.experimental.LazyApplication' and
Robolectric makes no guarantees if a test modifies this field during
execution.

Replacing 'application' with 'getApplication()' resolves this
deprecation warning.
Warning: "'assertTrue()' can be simplified to 'assertEquals()'"
Warnings:
- "Test class name 'ReleaseStack_ThemeTestWPCom' doesn't match
regex '[A-Z][A-Za-z\d]*Test(s|Case)?|Test[A-Z][A-Za-z\d]*|IT(.*)|(.*)
IT(Case)?'"
- "Test class name 'ReleaseStack_ThemeTestJetpack' doesn't match
regex '[A-Z][A-Za-z\d]*Test(s|Case)?|Test[A-Z][A-Za-z\d]*|IT(.*)|(.*)
IT(Case)?'"
Warning: "'assertTrue()' can be simplified to 'assertEquals()'"
Warning: "'assertTrue()' can be simplified to 'assertSame()'"
Warning: "'assertFalse()' can be simplified to 'assertNotEquals()'"
Warnings:
- "Actual value of parameter 'username' is always
'BuildConfig.TEST_WPCOM_USERNAME_SINGLE_JETPACK_ONLY'"
- "Actual value of parameter 'username' is always
'BuildConfig.TEST_WPCOM_USERNAME_SINGLE_JETPACK_ONLY'"
Warnings:
- "Inner class 'WPComThemeListResponse' may be 'static'"
- "Inner class 'WPComThemeMobileFriendlyTaxonomy' may be 'static'"
- "Inner class 'WPComThemeTaxonomies' may be 'static'"
Warning: "Inner class 'JetpackThemeListResponse' may be 'static'"
A theme's id is not a number, at least not anymore. Instead it is a text
like 'fewer' or 'mayland'. As such one cannot activate, install or
delete a theme if that edit text is not updated to a 'text' input type.
FYI: 'n-a' stands for 'nullability annotations'.

PS: This 'NotNullFieldNotInitialized' warning got suppressed because a
'response' class can never have its fields initialized via a constructor
initialization, or otherwise for that matter.
FYI: 'n-a' stands for 'nullability annotations'.

PS: This 'NotNullFieldNotInitialized' warning got suppressed because a
'response' class can never have its fields initialized via a constructor
initialization, or otherwise for that matter.

------------------------------------------------------------------------

Also, you will note that the 'author', 'author_uri', 'theme_uri' and
'version' fields are being defined as non-null. If you compare them
fields on the 'WordPress' equivalent response, you will notice them
being nullable there. My testing revealed that this is indeed the case
with Jetpack themes and thus those were marked as non-null here.
From the responses I tested, both, for WP.com and Jetpack, it seems that
'screenshot' is empty ("") instead of null, that is, when no screenshot
is set on a specific theme.
@antonis
Copy link

antonis commented Nov 3, 2023

Thank you for tackling this @ParaskP7 🙇

I added you as the main reviewer, randomly so, since I just wanted someone from the Jetpack/WordPress mobile team to be aware of and sign-off on that change for both.

I plan to go through this early next week.

Feel free to merge this PR directly yourself if you deem so.

Thank you for the clarification. I'll remove the Not Ready for Merge label and merge it when ready.

@ParaskP7
Copy link
Contributor Author

ParaskP7 commented Nov 3, 2023

I plan to go through this early next week.

Awesome, thank you for the heads-up on that @antonis , totally appreciated! 🙇 ❤️

…ndroid into analysis/add-missing-nullability-annotations-to-theme-client-classes
Copy link

@antonis antonis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for improving our codebase @ParaskP7 🙇
I went through the code and I don't have any comments on the code changes thanks to your detailed commit messages 🏅 I also smoke tested the WP/JP app and the example FluxC app and everything worked as expected for me on a Pixel 5 (Android 14) 🎉

@antonis antonis merged commit 7a028a4 into trunk Nov 7, 2023
2 checks passed
@antonis antonis deleted the analysis/add-missing-nullability-annotations-to-theme-client-classes branch November 7, 2023 14:09
@ParaskP7
Copy link
Contributor Author

ParaskP7 commented Nov 7, 2023

Awesome @antonis , thank you so much for reviewing, testing, and following the merge instructions, including merging this yourself, you rock! 🙇 ❤️ 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants