Add a test for a useless @Contract by msridhar · Pull Request #1346 · uber/NullAway (original) (raw)
Walkthrough
A new static method uselessContract(@nullable Object o) was added to the NullnessChecker test class, accompanied by a corresponding test case. This method is annotated with a contract and returns a nullable object. The test case exercises the contract behavior and verifies that diagnostics are still produced when using this contract configuration.
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 (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title 'Add a test for a useless @contract' is clear and directly summarizes the main change: adding a new test case for contract annotation behavior in NullAway. |
✨ Finishing touches
- 📝 Generate docstrings 🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
- Commit unit tests in branch
contract-test
📜 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 39d65f8 and 4fc1af9.
📒 Files selected for processing (1)
nullaway/src/test/java/com/uber/nullaway/ContractsTests.java(2 hunks) 🧰 Additional context used 🧠 Learnings (1) 📚 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/java/com/uber/nullaway/ContractsTests.java🔇 Additional comments (2)
nullaway/src/test/java/com/uber/nullaway/ContractsTests.java (2)
176-178:uselessContractcontract and signature correctly model a “no-op” contract for NullAway.The
@Contract("null -> null")onuselessContractmatches the implementation (return o;) and keeps the method return type@Nullable, so it doesn’t accidentally imply non-null on non-null inputs. This cleanly encodes the “useless” contract scenario the PR is targeting.
195-199: Newtest4precisely asserts that@Contract("null -> null")doesn’t suppress the nullable-return diagnostic.Using a non-null
Object o4argument while expecting// BUG: Diagnostic contains: returning @Nullable expressionis the right way to guard against misinterpreting the contract as strengthening the return type; this directly tests the PR objective.
Tip
📝 Customizable high-level summaries are now available in beta!
You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
- Provide your own instructions using the
high_level_summary_instructionssetting. - Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
- Use
high_level_summary_in_walkthroughto move the summary from the description to the walkthrough section.
Example instruction:
"Divide the high-level summary into five sections:
- 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
- 📓 References — List relevant issues, discussions, documentation, or related PRs.
- 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
- 📊 Contributor Summary — Include a Markdown table showing contributions:
| Contributor | Lines Added | Lines Removed | Files Changed |- ✔️ Additional Notes — Add any extra reviewer context.
Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.
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.