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 All SDK Override Methods for Fragments #19004

Conversation

ParaskP7
Copy link
Contributor

@ParaskP7 ParaskP7 commented Aug 18, 2023

Parent #18909

This PR adds any missing nullability annotation to all SDK override methods on Fragment classes.

FYI: Note the fact that Dialog Fragment and Preference Fragment related classes are excluded from this PR and instead will be handled in separate isolated PRs (here and here).


Note that the nullability information wasn't available on all of the super method signatures and thus I had to make a call on making a method's parameter and/or its return value either NonNull or Nullable. Thus, and in order to make the best call possible, I researched each such method separately (*), used ChatGPT to increase my confidence, and based my call on existing usages of such methods.

While doing so I also documented all those methods and grouped them per package, per library, see below:

Methods + Nullability
android
  os
    Parcelable.java (Interface) -> Creator<T> (Interface)
    - @NonNull T createFromParcel(@NonNull Parcel source) { ... } (*)
    - @NonNull T[] newArray(int size) { ... } (*)
  app
    Fragment.java (Class)
    - void onActivityCreated(@Nullable Bundle savedInstanceState) { ... }
    - void onCreate(@Nullable Bundle savedInstanceState) { ... }
    - @Nullable View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { ... } (*)
    - void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { .. } (*)
    - void onPrepareOptionsMenu(@NonNull Menu menu) { ... } (*)
    - boolean onOptionsItemSelected(@NonNull MenuItem item) { ... } (*)
  view
    View.java (Class) -> OnClickListener (Interface)
    - void onClick(@NonNull View v) { ... } (*)
    View.java (Class) -> OnLongClickListener (Interface)
    - boolean onLongClick(@NonNull View v) { ... } (*)
    View.java (Class) -> OnFocusChangeListener (Interface)
    - void onFocusChange(@NonNull View v, boolean hasFocus) { ... } (*)
    View.java (Class) -> OnTouchListener (Interface)
    - boolean onTouch(@NonNull View v, @NonNull MotionEvent event) { ... } (*)
    View.java (Class) -> OnDragListener (Interface)
    - boolean onDrag(@NonNull View v, @NonNull DragEvent dragEvent) { ... } (*)
    View.java (Class) -> OnKeyListener (Interface)
    - boolean onKey(@NonNull View v, int keyCode, @NonNull KeyEvent event) { ... } (*)
    View.java (Class) -> OnKeyListener (Interface)
    - boolean onKey(@NonNull View v, int keyCode, @NonNull KeyEvent event) { ... } (*)
    MenuItem.java (Interface) -> OnActionExpandListener (Interface)
    - boolean onMenuItemActionExpand(@NonNull MenuItem item) { ... }
    - boolean onMenuItemActionCollapse(@NonNull MenuItem item) { ... }
    animation
      Animation.java (Abstract Class) -> AnimationListener (Interface)
      - void onAnimationStart(@NonNull Animation animation) { ... } (*)
      - void onAnimationEnd(@NonNull Animation animation) { ... } (*)
      - void onAnimationRepeat(@NonNull Animation animation) { ... } (*)
  widget
    AbsListView.java (Abstract Class) -> RecyclerListener (Interface)
    - void onMovedToScrapHeap(@NonNull View view) { ... } (*)
  content
    DialogInterface.java (Interface) -> OnClickListener (Interface)
    - void onClick(@Nullable DialogInterface dialog, int which) { ... } (*)
  text
    TextWatcher.java (Interface)
    - void beforeTextChanged(@NonNull CharSequence s, int start, int count, int after) { ... } (*)
    - void onTextChanged(@NonNull CharSequence s, int start, int before, int count) { ... } (*)
    - void afterTextChanged(@NonNull Editable s) { ... } (*) + (⚠️)
  webkit
    WebChromeClient.java (Class)
    - void onPageFinished(@NonNull WebView view, @Nullable String url) { ... } (*)
    WebViewClient.java (Class)
    - void onProgressChanged(@NonNull WebView view, int newProgress) { ... } (*)
    - void onReceivedTitle(@NonNull WebView view, @Nullable String title) { ... } (*)
androidx
  fragment
    app
      Fragment.java (Class)
      - void onAttach(@NonNull Context context) { ... }
      - void onAttach(@NonNull Activity activity) { ... }
      - void setArguments(@Nullable Bundle args) { ... }
      - void onActivityCreated(@Nullable Bundle savedInstanceState) { ... }
      - void onCreate(@Nullable Bundle savedInstanceState) { ... }
      - @Nullable View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { ... }
      - void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { ... }
      - void onSaveInstanceState(@NonNull Bundle outState) { ... }
      - void onViewStateRestored(@Nullable Bundle savedInstanceState) { ... }
      - void onConfigurationChanged(@NonNull Configuration newConfig) { ... }
      - void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { ... }
      - void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { ... }
      - void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { ... }
      - void onPrepareOptionsMenu(@NonNull Menu menu) { ... }
      - boolean onOptionsItemSelected(@NonNull MenuItem item) { ... }
      - void onCreateContextMenu(@NonNull ContextMenu menu, @NonNull View v, @Nullable ContextMenuInfo menuInfo) { ... }
      - boolean onContextItemSelected(@NonNull MenuItem item) { ... }
      FragmentStatePagerAdapter.java (Abstract Class)
      - @NonNull Fragment getItem(int position) { ... }
      - void restoreState(@Nullable Parcelable state, @Nullable ClassLoader loader) { ... }
      - @Nullable Parcelable saveState() { ... }
  appcompat
    widget
      SearchView.java (Class) -> OnQueryTextListener (Interface)
      - boolean onQueryTextSubmit(@NonNull String query) { ... } (*) + (⚠️)
      - boolean onQueryTextChange(@NonNull String newText) { ... } (*) + (⚠️)
    view
      ActionMode.java (Abstract Class) -> Callback (Interface)
      - boolean onCreateActionMode(@NonNull ActionMode mode, @NonNull Menu menu) { ... } (*)
      - boolean onPrepareActionMode(@NonNull ActionMode mode, @NonNull Menu menu) { ... } (*)
      - boolean onActionItemClicked(@NonNull ActionMode mode, @NonNull MenuItem item) { ... } (*)
      - void onDestroyActionMode(@NonNull ActionMode mode) { ... } (*)
  recyclerview
    widget
      RecyclerView.java (Class) -> Adapter<VH extends ViewHolder> (Abstract Class)
      - @NonNull VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { ... }
      - void onBindViewHolder(@NonNull VH holder, int position) { ... }
      RecyclerView.java (Class) -> RecyclerListener (Interface)
      - void onViewRecycled(@NonNull ViewHolder holder) { ... }
      RecyclerView.java (Class) -> OnScrollListener (Interface)
      - void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { ... }
      - void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { ... }
  lifecycle
    Observer.java (Interface)
    - void onChanged(@NonNull T value) { ... } (*)
com
  google
    android
      material
        tabs
          TabLayout.java (Class) -> BaseOnTabSelectedListener<T extends Tab> (Interface)
          - void onTabSelected(@NonNull TabLayout.Tab tab) { ... } (*)
          - void onTabUnselected(@NonNull TabLayout.Tab tab) { ... } (*)
          - void onTabReselected(@NonNull TabLayout.Tab tab) { ... } (*)
Methods + Nullability to Triple Check
android.text.TextWatcher.java (Interface)
- void afterTextChanged(@NonNull Editable s) { ... } (*) + (⚠️)
androidx.appcompat.widget.SearchView.java (Class) -> OnQueryTextListener (Interface)
- boolean onQueryTextSubmit(@NonNull String query) { ... } (*) + (⚠️)
- boolean onQueryTextChange(@NonNull String newText) { ... } (*) + (⚠️)

(*): Nullability info not available on the super method signature and thus arbitrary added.
(⚠️): Better to double (triple) check that this @NonNull added won't cause us any trouble!


Nullability Annotation List:

  1. Add missing n-a to sdk override methods for editor abstract
  2. Add missing n-a to sdk override methods for aztec editor
  3. Add missing n-a to sdk override methods for gutenberg editor
  4. Add missing n-a to sdk override methods for gutenberg ctr
  5. Add missing n-a to sdk override methods for shared intent rec
  6. Add missing n-a to sdk override methods for login epilogue
  7. Add missing n-a to sdk override methods for signup epilogue
  8. Add missing n-a to sdk override methods for comment detail
  9. Add missing n-a to sdk override methods for history detail
  10. Add missing n-a to sdk override methods for media grid
  11. Add missing n-a to sdk override methods for media preview
  12. Add missing n-a to sdk override methods for people invite
  13. Add missing n-a to sdk override methods for people list
  14. Add missing n-a to sdk override methods for person detail
  15. Add missing n-a to sdk override methods for plugin list
  16. Add missing n-a to sdk override methods for edit post settings
  17. Add missing n-a to sdk override methods for tags
  18. Add missing n-a to sdk override methods for my profile
  19. Add missing n-a to sdk override methods for site settings td
  20. Add missing n-a to sdk override methods for publicize detail
  21. Add missing n-a to sdk override methods for publicize list
  22. Add missing n-a to sdk override methods for publicize web view
  23. Add missing n-a to sdk override methods for reader blog
  24. Add missing n-a to sdk override methods for reader photo vwr
  25. Add missing n-a to sdk override methods for reader post list
  26. Add missing n-a to sdk override methods for reader post wvc
  27. Add missing n-a to sdk override methods for reader tag
  28. Add missing n-a to sdk override methods for stock media rtn
  29. Add missing n-a to sdk override methods for them browser

To test:

  1. Smoke test both, the WordPress and Jetpack apps, and see if everything is working as expected.

Regression Notes

  1. Potential unintended areas of impact

    • N/A
  2. What I did to test those areas of impact (or what existing automated tests I relied on)

    • See To test section above.
  3. What automated tests I added (or what prevented me from doing so)

    • N/A

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

UI Changes testing checklist:

  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • Talkback.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • Large and small screen sizes. (Tablet and smaller phones)
  • Multi-tasking: Split screen and Pop-up view. (Android 10 or higher)

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'.
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'.
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'.
@ParaskP7 ParaskP7 added the Core label Aug 18, 2023
@wpmobilebot
Copy link
Contributor

WordPress📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress WordPress
FlavorJalapeno
Build TypeDebug
Versionpr19004-164ee6b
Commit164ee6b
Direct Downloadwordpress-prototype-build-pr19004-164ee6b.apk
Note: Google Login is not supported on these builds.

@wpmobilebot
Copy link
Contributor

Jetpack📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack Jetpack
FlavorJalapeno
Build TypeDebug
Versionpr19004-164ee6b
Commit164ee6b
Direct Downloadjetpack-prototype-build-pr19004-164ee6b.apk
Note: Google Login is not supported on these builds.

@ParaskP7
Copy link
Contributor Author

As per this I am now closing this PR and will be creating vertical type of PRs (one PR per @Override method), for both, the safe (1.) type of PRs and the more risky (2.) type of PRs. Cc @mkevins

@ParaskP7 ParaskP7 closed this Aug 29, 2023
@jkmassel jkmassel deleted the analysis/add-missing-nullability-annotations-to-all-sdk-override-methods-for-fragments branch October 17, 2024 18:59
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