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 Media Network Client Classes (safe) #2878

Conversation

ParaskP7
Copy link
Contributor

@ParaskP7 ParaskP7 commented Oct 23, 2023

Parent #2798
Accompanying JP/WPAndroid#19428

This PR adds any missing nullability annotation to MediaRestClient.java and MediaXMLRPCClient.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 MediaStore and their usages with our main clients suggests that this store is being utilizing by both, the JP/WPAndroid and WCAndroid clients.


PS.1: @AjeshRPai 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. Feel free to merge this PR directly yourself if you deem so.

PS.2: @0nko I am also adding you as an extra reviewer, randomly so, since I want someone from the WooCommerce mobile team to be aware of this change as well. However, there is no need for you to review it as well, thus duplicating the review work. Having one team member from either of the mobile teams reviewing and testing this change is enough for this change.


Nullability Annotation List:

  1. Add missing nn-a to ok http client field on media clients
  2. Add missing nn-a to media response utils field on media rest
  3. Add missing nn-a to current upload calls field on media clts
  4. Add missing n-a to on progress on media clients
  5. Add missing n-a to push media on media clients
  6. Add missing n-a to upload media on media clients
  7. Add missing n-a to fetch media list on media clients
  8. Add missing n-a to fetch media on media clients
  9. Add missing n-a to delete media on media clients
  10. Add missing n-a to cancel upload on media clients
  11. Add missing n-a to get media list frm response on media xmlrpc
  12. Add missing n-a to get map frm upload response on media xmlrpc
  13. Add missing n-a to deprecated upload response on media xmlrpc
  14. Add missing n-a to media from xmlrpc response on media xmlrpc
  15. Add missing n-a to get basic params on media xmlrpc client
  16. Add missing n-a to is 404 response on media xmlrpc client
  17. Add missing n-a to media error from exception on media xmlrpc
  18. Add missing n-a to get file (url) for size on media xmlrpc
  19. Add missing n-a to media payload on media store
  20. Add missing n-a to upload mediaPayload on media store
  21. Add missing n-a to fetch media list payload on media store
  22. Add missing n-a to fetch media list response pl on media store
  23. Add missing n-a to progress payload on media store
  24. Add missing n-a to cancel media payload on media store
  25. Add missing n-a to counting sink on base upload request body
  26. Add missing nl-a to s method parameter on media fragment
  27. Add missing nn-a to multi field on media wp com rest response
  28. Add missing n-a to media wp com rest response fields

Nullability Checks List:

  1. Un-guard usages of media error on media rest client
  2. Guard usages of media list on media rest client
  3. Guard usages of media title on media xmlrpc client
  4. Guard usages of params get key on rest upload request body

Warnings Resolutions List:

  1. Add missing final to ok http client field on media clients
  2. Add missing final to media response utils field on media rest
  3. Add missing final to cnt upload calls field on media clients
  4. Change type of request to include the missing generic type
  5. Remove unnecessary is response null checks on media xmlrpc clt
  6. Remove io exception from throws list on media xmlrpc client
  7. Replace string/charset with std charsets utf8 on media xmlrpc
  8. Simplify if/else on media xmlrpc client
  9. Create missing switch cases for media store errors
  10. Remove unnecessary is split msg null checks on media store
  11. Replace explicit type argument with <> on on media changed
  12. Use inserted media on instantiate media model store method
  13. Replace fi stream with try with resource on xmlrpc upload rb
  14. Make inner classes static on media wp com rest response
  15. Delete unused thumbnails field on media wp com rest response
  16. Delete unused multiple fields on media wp com rest response

Warnings Suppression List:

  1. Suppress use of parameterized class map on media xmlrpc client
  2. Suppress raw types warning on media store
  3. Suppress unused warning on media related payload constructor
  4. Suppress unused warnings on get related media methods
  5. Suppress same parameter value warning on media store
  6. Suppress request body create deprecation on rest upload rb
  7. Suppress string escape utils deprecation on xmlrpc upload rb

Refactor List:

  1. Reformat media rest client
  2. Reformat media xmlrpc client
  3. Replace anonymous classes with lambda on media rest client
  4. Replace anonymous classes with lambda on media xmlrpc client
  5. Reformat error responses on media clients
  6. Reformat media store

Test List:

  1. Suppress kotlin internal in java on media store test
  2. Add missing final to media store on media store test
  3. Resolve robolectric related application deprecation warnings
  4. Simplify assert true assertions on media store test
  5. Suppress new class naming convention for connected tests
  6. Suppress throws count for ms media test
  7. Simplify new media model helper func. on ms media test
  8. Guard usages of remote id queue poll on ms media test
  9. Fix typo with we're on ms media test
  10. Simplify new media model helper function on ms upload test
  11. Remove unnecessary media path length on ms upload test
  12. Make create new post method void on ms upload test
  13. Remove interrupted exception from throws list on ms upload test
  14. Insert <p> on ms upload store test
  15. Simplify new media model helper function on ms upload store test
  16. Remove unnecessary media path length on ms upload store test
  17. Delete unused account store file on rs media test jetpack
  18. Simplify new media model helper function on rs media test jetpack
  19. Remove unnecessary media path length on rs media test jetpack
  20. Simplify new media model helper function on rs media test wp com
  21. Simplify new media model helper function on rs media test xmlrpc

Docs List:

  1. Replace url with html link on media rest client
  2. Replace urls with html links on media xmlrpc client
  3. Improve documentation on rest upload request body
  4. Improve documentation on base upload request body
  5. Improve documentation on media wp com rest response

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 MEDIA screen. Verify everything is working as expected.
  • In addition to the above, using local-builds.gradle on JP/WPAndroid, smoke test any media 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:
  • Furthermore, using local-builds.gradle on WCAndroid, smoke test any media related functionality 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):

  • Create a new self-hosted WordPress site for XMLRPC testing purposes (jurassic.ninja).
  • Smoke test the FluxC Example app via the MEDIA screen. Verify everything is working as expected.
  • In addition to the above, using local-builds.gradle on JP/WPAndroid, smoke test any media 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:
  • Furthermore, using local-builds.gradle on WCAndroid, smoke test any media related functionality 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:
[JP/WP] Media Screens [MediaBrowserActivity.java + MediaGridFragment.kt + MediaSettingsActivity.java + MediaPreviewActivity.java + MediaPreviewFragment.java]

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

  • Go to Media screen, verify it is shown and functioning as expected.
  • For example try changing tabs, searching and adding a new media.
  • Tap on any media and verify that the Media Settings screen is shown and functioning as expected.
  • For example try updating the media title or adding a media description.
  • Tap on the media preview and verify that the Media Preview screen is shown and functioning as expected.
  • For example try swipe left-right to navigate between media previews.
[WC] Photos Screens [ProductDetailFragment.java + ProductImagesFragment.kt + ProductImageViewerFragment.kt]
  • Go to Products tab and tap on any product.
  • Tap on any photo on top and verify that the Photos screen is shown and functioning as expected.
  • For example try adding a new photo, select an upload method, and wait for the photo to be uploaded.
  • Tap on the photo preview and verify that the Photo Preview screen is shown and functioning as expected.
  • For example try swipe left-right to navigate between photo previews.

Merge instructions:

  1. Wait for the accompanying JP/WPAndroid#19428 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#19428 client PR.

Warning: "Field 'mOkHttpClient' may be 'final'"
Warning: "Field 'mMediaResponseUtils' may be 'final'"
Warning: "Field 'mCurrentUploadCalls' may be 'final'"
Warning: "Raw use of parameterized class 'WPComGsonRequest'"
Warning: "Link specified as plain text"
Warning: "Condition 'response == null' covered by subsequent condition
'!(response instanceof Boolean)'"
Warning: "Link specified as plain text"
Warning: “Exception ‘java.io.IOException’ is never thrown in the method”
Warnings:
- "Raw use of parameterized class 'Map'"
- "Raw use of parameterized class 'HashMap'"
Warning: "StandardCharsets.UTF_8 can be used instead"
Warning: "'if' statement can be simplified"
FYI: 'nn-a' stands for 'non-null annotation'.
FYI: 'nn-a' stands for 'non-null annotation'.
FYI: 'nn-a' stands for 'non-null annotation'.
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'.
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'
FYI: 'n-a' stands for 'nullability annotations'
Warnings:
- "Blank line will be ignored"
- "Link specified as plain text"
FYI: 'n-a' stands for 'nullability annotations'
Warnings:
- "Blank line will be ignored"
- "Link specified as plain text"
Warnings:
- "Inner class 'MultipleMediaResponse' may be 'static'"
- "Inner class 'Thumbnails' may be 'static'"
FYI: 'nl-a' stands for 'nullable annotation'.
FYI: 'nn-a' stands for 'non-null 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, note that as part of this change, the 'response' that was
previously considered '@nullable' has been updated to '@nonnull' as it
doesn't seem that a nullable response to be valid, or part of a specific
valid flow. The fact that 'MediaWPRESTResponse.kt' and
'BaseWPV2MediaRestClient.kt' is also working with a '@nonnull' response
give this change some extra confidence.
FYI: 'n-a' stands for 'nullability annotations'.
…ndroid into analysis/add-missing-nullability-annotations-to-media-client-classes
Copy link
Contributor

@AjeshRPai AjeshRPai left a comment

Choose a reason for hiding this comment

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

Hey @ParaskP7

I looked at this PR’s code changes and smoke-tested the companion WP PR. Everything looks good to me 👍🏼

I am approving but not merging since this change affects WC. I am unsure whether we should also wait until someone from WC approves this change.

Please feel free to merge this PR at your convenience

@ParaskP7
Copy link
Contributor Author

Great, thanks for reviewing and testing this @AjeshRPai , I am glad that everything is working as expected! 🙇 ❤️ 🚀

FYI: @0nko I'll be also waiting any input from you, else a quick 👍 , that is before proceeding with merging this, just so that I know you are aware of this change merging into trunk before it happens.

Copy link
Contributor

@0nko 0nko left a comment

Choose a reason for hiding this comment

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

I briefly scanned the code and I see no issue with it. I'm currently having some issues with my build environment so I can't test it unfortunately. But since @AjeshRPai already smoke-tested it, I think we should be fine. Thanks for working on this @ParaskP7 and sorry about the wait.

@ParaskP7
Copy link
Contributor Author

Great, thanks you so much for the skim review @0nko , much appreciated! 🙇 ❤️

I'm currently having some issues with my build environment so I can't test it unfortunately. But since @AjeshRPai already smoke-tested it, I think we should be fine.

Let me know if I can help with your build environment as it would be actually great if you could test this with WCAndroid as well. FYI: To my understanding, Ajesh tested this only with JP/WPAndroid. 🙏

@0nko
Copy link
Contributor

0nko commented Oct 27, 2023

@ParaskP7 I've smoke-tested the app and everything works as expected! :shipit:

@ParaskP7
Copy link
Contributor Author

Awesome, thanks so much for getting back to this with some additional testing @0nko , 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.

3 participants