null") is not being interpreted incorrectly. Test-only change. Summary by CodeRabbit Tests Enhanced test coverage for contract null-safety validation s...">

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


📜 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)

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 (2)

176-178: uselessContract contract and signature correctly model a “no-op” contract for NullAway.

The @Contract("null -> null") on uselessContract matches 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: New test4 precisely asserts that @Contract("null -> null") doesn’t suppress the nullable-return diagnostic.

Using a non-null Object o4 argument while expecting // BUG: Diagnostic contains: returning @Nullable expression is 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.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ 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.