Better support for some contracts with boolean argument constraints#1447
Better support for some contracts with boolean argument constraints#1447
Conversation
WalkthroughAdds handling for compile-time constant boolean antecedents in contract analysis. ContractHandler now, during onDataflowVisitMethodInvocation, inspects boolean-literal antecedents and checks the corresponding invocation argument via ASTHelpers.constValue on an ExpressionTree: if the argument is a compile-time boolean matching the antecedent the clause continues, otherwise the clause is marked unsupported and processing breaks. The change adds an import for com.sun.source.tree.ExpressionTree and introduces an early short-circuit path for boolean-constraint handling. Three tests exercising boolean and mixed boolean/null contracts were added. Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@nullaway/src/test/java/com/uber/nullaway/ContractsTests.java`:
- Around line 777-779: The test currently calls nonNullWhenPassedFalse(b || !b)
with a "false -> !null" contract but b || !b is always true, so the warning is a
true positive; to make this a false-positive test change the call to
nonNullWhenPassedTrue(b || !b) (the method with the "true -> !null" contract) so
the contract should guarantee non-null at runtime but NullAway still emits a
warning, or alternatively update the comment and the expected diagnostic to
reflect that this is a true positive if you intend to keep calling
nonNullWhenPassedFalse.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1447 +/- ##
============================================
+ Coverage 88.40% 88.41% +0.01%
- Complexity 2712 2714 +2
============================================
Files 99 99
Lines 9007 9015 +8
Branches 1799 1801 +2
============================================
+ Hits 7963 7971 +8
Misses 517 517
Partials 527 527 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Fixes #1232
We now support contracts like
@Contract("false -> !null"). This turned out to be easier than I thought (Codex helped :-) ). The support only detects cases when the literalfalseortrueis passed at the call site. And, we currently cannot verify these contracts; we can only use them at call sites.Summary by CodeRabbit
Improvements
Tests
✏️ Tip: You can customize this high-level summary in your review settings.