Skip to content
This repository has been archived by the owner on Feb 4, 2025. It is now read-only.

[Nullability Annotations to Java Classes] Add Missing Nullability Annotations to Media Model Classes (breaking) #2886

Conversation

ParaskP7
Copy link
Contributor

@ParaskP7 ParaskP7 commented Oct 31, 2023

Parent #2799
Closes #2832

This PR adds any missing nullability annotation to MediaModel.java model and all related store & sql-util classes.

FYI: This change is breaking, meaning that any client that depended on the MediaModel.java model should update to the new APIs (non-default constructors) as the existing API (default constructor) are now deprecated. As such, this change is inherently risky, meaning that there are compile-time changes associated with this change and thus needs testing to verify correctness, both on the library's and client's side.

PS: Any other changes on any other class are just some propagating missing nullability annotation changes, which stem from the main set of classes being updated, this PR's focus, plus, some other extra minor analysis, refactor and test related changes.


PS.1: @AjeshRPai I added you as the main reviewer, not so randomly (it being a continuation of #2878), 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.

PS.2: @0nko I am also adding you as an extra reviewer, not so randomly (it being a continuation of #2878), 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 Annotations List (Model):

  1. Add missing final keyword to field name on media fields enum
  2. Add missing nl-a to equals parameter on media model
  3. Add missing nl-a to upload state field on media model
  4. Add missing nn-a to fields to update field on media model
  5. Add missing n-a to media model
  6. Add default and non-default constructors for media model (breaking)

Nullability Annotations List (Store):

  1. Add missing n-a to media error type enum on media store
  2. Add missing n-a to media error on media store
  3. Add missing n-a to upload stock me type enum on media store
  4. Add missing n-a to upload stock me on media store
  5. Add missing n-a to on media changed on media store
  6. Add missing n-a to on media list fetched on media store
  7. Add missing n-a to on media uploaded on media store
  8. Add missing n-a to get (all) site media (count) on media store
  9. Add missing n-a to has/get site media with id on media store
  10. Add missing n-a to get media with local id on media store
  11. Add missing n-a to get site media with ids on media store
  12. Add missing n-a to get images/videos/audio/docs on media store
  13. Add missing n-a to get site images excl. ids on media store
  14. Add missing n-a to match site media related on media store
  15. Add missing n-a to get local site media on media store
  16. Add missing n-a to get thumbnail url for smi on media store
  17. Add missing n-a to search site related on media store
  18. Add missing n-a to match post media related on media store
  19. Add missing n-a to remove media on media store
  20. Add missing n-a to perform upload stock media on media store
  21. Add missing n-a to handle stock media uploaded on media store

Nullability Annotations List (SqlUtils):

  1. Add missing n-a to get media with sq on media sql utils
  2. Add missing n-a to get with states related on media sql utils
  3. Add missing n-a to get insert media related on media sql utils
  4. Add missing n-a to get delete media related on media sql utils

Nullability Annotations List (Utils):

  1. Add missing n-a to is (supported) related on media utils
  2. Add missing n-a to get mime type for extension on media utils
  3. Add missing n-a to can read file on media utils
  4. Add missing n-a to get extension on media utils
  5. Add missing n-a to get file name on media utils
  6. Add missing n-a to strip location on media utils

Warnings Resolution List:

  1. Make strip location method void on media utils
  2. Make delete related methods void on media sql utils

Warnings Suppression List:

  1. Suppress condition covered by further condition warning
  2. Suppress unused warning on media model
  3. Suppress unused warning on media utils
  4. Suppress boolean method is always inverted warn on media utils
  5. Suppress unused warning on media sql utils

Refactor List:

  1. Move static not deleted states field to top on media store

Test List:

  1. Use property access syntax on media error test
  2. Simplify assert true assertion on media test utils
  3. Reformat mocked stack media test
  4. Add missing final to media store on media utils test
  5. Add missing final to media store on media sql utils test
  6. Suppress constant value warning on media sql utils test
  7. Delete unneeded test match post media test on media sql utils test
  8. Remove interrupted exception from throws list on media su test
  9. Simplify insert helper functions on on media sql utils test

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#19506 to be reviewed and approved.
  2. Wait for the accompanying WCAndroid#10078 to be reviewed and approved.
  3. Remove the [PR] Not Ready for Merge label.
  4. Merge this PR.
  5. Follow-up with the merge instructions on the accompanying JP/WPAndroid#19506 client PR.
  6. Follow-up with the merge instructions on the accompanying WCAndroid#10078 client PR.

Warnings:
- "Non-final field 'mFieldName' in enum 'MediaFields'"
- "Field 'mFieldName' may be 'final'"
Warning: "Condition 'other == null' covered by subsequent condition
'!(other instanceof MediaModel)'"

FYI: One could resolve this warning, simply by removing the unnecessary
'other == null' condition, but this would change the 'equals(...)' logic
and possible introduce some kind of a regression, most liked performance
wise. Thus, it is better to ignore this atm, just by suppressing it, and
call this out of scope.
This 'setFieldsToUpdate(...)' method is actually meant to and used
by client apps (ie. JP/WPAndroid). They just seem unused as they are
not being directly used via the example app or any unit/ui tests within
this repo.
FYI: 'n-a' stands for 'nullable annotations'.
FYI: 'n-a' stands for 'nullable annotations'.
FYI: 'n-a' stands for 'non-null annotations'.
FYI: 'n-a' stands for 'nullability annotations'.

PS: This 'NotNullFieldNotInitialized' warning got suppressed because a
table related 'model' class can never have its fields initialized via a
constructor initialization, or otherwise for that matter.
This is done so that clients of that model, clients like JP/WPAndroid
and WCAndroid, when trying to manually instantiating such a model, they
will always use the non-default constructor, and thus always provide at
least an 'localSiteId' and 'mediaId' argument (for an existing media).

The empty default constructor was added because '@table' related models
need to have one such constructor. Otherwise, its 'Mapper' related
auto-generated class would fail to compile, in this case the
'MediaModelMapper.java' class.

Also, a full-arguments constructor was added, which should be the
preferred and goto constructor for most cases.

FYI: The trick I used to first '@deprecated' this constructor is to help
clients avoid using this constructor in the future, that is, when they
manually construct one. Suppressing the 'DeprecatedIsStillUsed' warning
was necessary because otherwise, even if every occurrence in the
codebase is being switched to the non-default constructor, the
auto-generated 'Mapper' related class will anyway use that default
constructor, thus this warning will persist no matter what.

PS: Note that on all the partial-argument constructors, an extra Javadoc
is added to help clients understand when and why to use each. For all
other cases, using the full-arguments constructor should be the
preferred and goto constructor.
FYI: 'n-a' stands for 'nullability annotations'
FYI: 'n-a' stands for 'nullability annotations'
Warning: "Use of getter method instead of property access syntax"
Warning: "'assertTrue()' can be simplified to 'assertEquals()'"
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'
FYI: 'n-a' stands for 'nullability annotations'

PS: Also, as part of this change, the 'getSiteImageCount(...)' method
got removed as it is only being used within 'MediaStoreTest'. The is
no reason to create a new method for 'getSiteImages(siteModel).size()'
alone, and more so, when no client apps like JP/WP/WCAndroid are using
it.
FYI: 'n-a' stands for 'nullability annotations'
FYI: 'n-a' stands for 'nullability annotations'

PS: Also, as part of this change, the 'getUnattachedSiteMediaCount(...)'
method got removed as it is only being used within 'MediaStoreTest'. The
is no reason to have a new method for 'getSiteImages(siteModel).size()'
alone, and more so, when no client apps like JP/WP/WCAndroid are using
it.
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'
Warning: "Field 'mRandom' may be 'final'"
Warning: "Condition 'i < imageIds.size()' is always 'false'"
Warning: "Exception 'java.lang.InterruptedException' is never thrown in
the method"
Warning: "Actual value of parameter 'num' is always
'MediaSqlUtilsTest.SMALL_TEST_POOL'"
@ParaskP7 ParaskP7 assigned ParaskP7 and unassigned ParaskP7 Oct 31, 2023
@ParaskP7 ParaskP7 requested review from 0nko and AjeshRPai October 31, 2023 16:45
@ParaskP7 ParaskP7 marked this pull request as ready for review October 31, 2023 16:45
@ParaskP7
Copy link
Contributor Author

FYI: Per the merge instructions within the PR description, I am going to create the accompanying JP/WPAndroid#TODO and WCAndroid#TODO PRs tomorrow. Until then, feel free to start the review process and test this PR with the FluxC Example app, since, you won't be able to test this with JP/WPAndroid or WCAndroid just yet. I'll let you know with another comment when each of those accompanying PRs get ready.

@ParaskP7
Copy link
Contributor Author

ParaskP7 commented Nov 1, 2023

FYI: The accompanying JP/WPAndroid#19506 PR is up and ready. As such, the code review on the JP/WPAndroid side can be fully completed. @AjeshRPai

@ParaskP7
Copy link
Contributor Author

ParaskP7 commented Nov 1, 2023

FYI: The accompanying WCAndroid#10078 PR is up and ready. As such, the code review on the WCAndroid side can be fully completed. @0nko

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've tested the FluxC Example app and I found no issues 👍.

As for the code changes, I've looked at the parts that are relevant to WCAndroid and it looks good. I'll let @AjeshRPai take a more detailed look since he's probably more familiar with it.

I already mentioned it in the WCAndroid PR, but we'll also want to update the MediaPicker library.

👏

@ParaskP7
Copy link
Contributor Author

ParaskP7 commented Nov 3, 2023

Thank you so much for reviewing, testing and approving these and the changes in the accompanying WCAndroid PR @0nko , you are awesome! 🙇 ❤️ 🚀

I already mentioned it in the WCAndroid PR, but we'll also want to update the MediaPicker library.

Oh true, this is interesting, I'll response to that in the accompanying WCAndroid PR, thanks for mentioning MediaPicker, I knew I picked the right person for this review! 💯 😊 💯

…ndroid into analysis/add-missing-nullability-annotations-to-media-model-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.

I have tested the changes in this PR using the accompanying wordpress-mobile/WordPress-Android#19506 and everything looks good to me 👍🏼

I am approving but not merging since this change also affects WCAndroid.

@ParaskP7
Copy link
Contributor Author

ParaskP7 commented Nov 8, 2023

Awesome, thank for reviewing and testing this @AjeshRPai , you rock! 🙇 ❤️ 🚀

FYI: I'll proceed with the merging myself. 🙏

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

Successfully merging this pull request may close these issues.

Nullability Annotations to Java Classes - SqlUtils & Model - Media
3 participants