Skip to content

Add Mockito annotations to default excluded field annotations#1418

Merged
msridhar merged 2 commits intouber:masterfrom
murdos:mockito-default-excluded-field-annotations
Dec 31, 2025
Merged

Add Mockito annotations to default excluded field annotations#1418
msridhar merged 2 commits intouber:masterfrom
murdos:mockito-default-excluded-field-annotations

Conversation

@murdos
Copy link
Copy Markdown
Contributor

@murdos murdos commented Dec 31, 2025

Fixes #280

Thank you for contributing to NullAway!

Please note that once you click "Create Pull Request" you will be asked to sign our Uber Contributor License Agreement via CLA assistant.

Before pressing the "Create Pull Request" button, please provide the following:

  • A description about what and why you are contributing, even if it's trivial.

  • The issue number(s) or PR number(s) in the description if you are contributing in response to those.

  • If applicable, unit tests.

Summary by CodeRabbit

  • New Features

    • Added support for Mockito field annotations (Captor, InjectMocks, Mock, Spy) to null-checking analysis, allowing these annotated fields to be properly recognized as initialized.
  • Tests

    • Added comprehensive test coverage for Mockito annotation handling.

✏️ Tip: You can customize this high-level summary in your review settings.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Dec 31, 2025

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 31, 2025

Walkthrough

This pull request adds support for Mockito field annotations to NullAway's excluded field annotations set. The change adds four Mockito annotations (org.mockito.Captor, org.mockito.InjectMocks, org.mockito.Mock, org.mockito.Spy) to DEFAULT_EXCLUDED_FIELD_ANNOT in ErrorProneCLIFlagsConfig.java, ensuring that fields annotated with these markers are treated as properly initialized and excluded from null-checking. The PR includes corresponding test data annotation definitions and an integration test method to verify the behavior.

Possibly related PRs

Suggested reviewers

  • msridhar
  • yuxincs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding Mockito annotations to the default excluded field annotations list.
Linked Issues check ✅ Passed The PR successfully addresses issue #280 by adding Mockito annotations (@mock, @SPY, @captor, @Injectmocks) to DEFAULT_EXCLUDED_FIELD_ANNOT and includes comprehensive test coverage.
Out of Scope Changes check ✅ Passed All changes are directly related to the objective of supporting Mockito annotations: configuration changes, test annotations, and test cases are all in scope.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8dd292f and 9775e12.

📒 Files selected for processing (6)
  • nullaway/src/main/java/com/uber/nullaway/ErrorProneCLIFlagsConfig.java
  • nullaway/src/test/java/com/uber/nullaway/FrameworkTests.java
  • nullaway/src/test/resources/com/uber/nullaway/testdata/mockito/Captor.java
  • nullaway/src/test/resources/com/uber/nullaway/testdata/mockito/InjectMocks.java
  • nullaway/src/test/resources/com/uber/nullaway/testdata/mockito/Mock.java
  • nullaway/src/test/resources/com/uber/nullaway/testdata/mockito/Spy.java
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.
Learnt from: msridhar
Repo: uber/NullAway PR: 1248
File: nullaway/src/main/java/com/uber/nullaway/generics/GenericsChecks.java:847-857
Timestamp: 2025-08-28T04:54:20.953Z
Learning: In NullAway's GenericsChecks.java, NewClassTree support for explicit type argument substitution requires more extensive changes beyond just modifying the conditional in compareGenericTypeParameterNullabilityForCall. The maintainers prefer to handle NewClassTree support in a separate follow-up rather than expanding the scope of PRs focused on specific issues like super constructor calls.
Learnt from: msridhar
Repo: uber/NullAway PR: 1259
File: jdk-recent-unit-tests/src/test/java/com/uber/nullaway/jdk17/SwitchTests.java:318-321
Timestamp: 2025-08-29T18:41:43.584Z
Learning: Classes annotated with NullMarked are analyzed by NullAway even if they are not in packages specified by the AnnotatedPackages configuration. The NullMarked annotation guarantees NullAway analysis.
📚 Learning: 2025-08-14T18:50:06.159Z
Learnt from: msridhar
Repo: uber/NullAway PR: 1245
File: guava-recent-unit-tests/src/test/java/com/uber/nullaway/guava/NullAwayGuavaParametricNullnessTests.java:101-102
Timestamp: 2025-08-14T18:50:06.159Z
Learning: In NullAway JSpecify tests, when JDK version requirements exist due to bytecode annotation reading capabilities, prefer failing tests over skipping them on unsupported versions to ensure CI catches regressions and enforces proper JDK version usage for developers.

Applied to files:

  • nullaway/src/test/resources/com/uber/nullaway/testdata/mockito/Mock.java
  • nullaway/src/main/java/com/uber/nullaway/ErrorProneCLIFlagsConfig.java
  • nullaway/src/test/java/com/uber/nullaway/FrameworkTests.java
🔇 Additional comments (6)
nullaway/src/test/resources/com/uber/nullaway/testdata/mockito/Captor.java (1)

1-13: LGTM! Test annotation definition matches Mockito's @captor.

The annotation definition correctly mirrors Mockito's @captor annotation with FIELD and PARAMETER targets and RUNTIME retention.

nullaway/src/main/java/com/uber/nullaway/ErrorProneCLIFlagsConfig.java (1)

182-185: LGTM! Mockito annotations correctly added to excluded field annotations.

The four Mockito annotations are appropriately added to DEFAULT_EXCLUDED_FIELD_ANNOT since Mockito initializes these fields at test runtime. The alphabetical ordering enhances maintainability.

nullaway/src/test/resources/com/uber/nullaway/testdata/mockito/Mock.java (1)

1-13: LGTM! Test annotation definition matches Mockito's @mock.

The annotation definition correctly mirrors Mockito's @mock annotation with FIELD and PARAMETER targets and RUNTIME retention.

nullaway/src/test/resources/com/uber/nullaway/testdata/mockito/Spy.java (1)

1-13: LGTM! Test annotation definition matches Mockito's @SPY.

The annotation definition correctly mirrors Mockito's @SPY annotation with FIELD target (not PARAMETER) and RUNTIME retention.

nullaway/src/test/resources/com/uber/nullaway/testdata/mockito/InjectMocks.java (1)

1-13: LGTM! Test annotation definition matches Mockito's @Injectmocks.

The annotation definition correctly mirrors Mockito's @Injectmocks annotation with FIELD target (not PARAMETER) and RUNTIME retention.

nullaway/src/test/java/com/uber/nullaway/FrameworkTests.java (1)

434-497: LGTM! Comprehensive test for Mockito field annotations.

The test method properly validates that all four Mockito annotations (@captor, @mock, @SPY, @Injectmocks) are correctly excluded from initialization checks. The test structure follows existing patterns in the file and provides good coverage for the fix.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.33%. Comparing base (8d65bf5) to head (48bef28).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1418   +/-   ##
=========================================
  Coverage     88.33%   88.33%           
  Complexity     2672     2672           
=========================================
  Files            98       98           
  Lines          8884     8884           
  Branches       1778     1778           
=========================================
  Hits           7848     7848           
  Misses          514      514           
  Partials        522      522           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@msridhar msridhar left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution @murdos!

@msridhar msridhar enabled auto-merge (squash) December 31, 2025 02:02
@msridhar msridhar merged commit 83f1c3d into uber:master Dec 31, 2025
11 checks passed
@murdos murdos deleted the mockito-default-excluded-field-annotations branch December 31, 2025 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible false positives using Mockito

3 participants