Repository navigation
Conversation
|
Victor Gabriel seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughNullAway treated every Severity of issue fixed: Low Merge Risk:
|
| private static boolean isCanonicalNameOfClassLiteral( | ||
| MethodInvocationTree invocation, Symbol.MethodSymbol callee, VisitorState state) { | ||
| if (!callee.name.contentEquals("getCanonicalName") | ||
| || !(ASTHelpers.getReceiver(invocation) instanceof MemberSelectTree literal) |
There was a problem hiding this comment.
Remove receiver parentheses before matching the class literal.
For (String.class).getCanonicalName().length(), ASTHelpers.getReceiver() preserves the parentheses. This check rejects the receiver, so the nullable warning remains. The pinned Error Prone implementation returns the selected expression unchanged. (raw.githubusercontent.com)
Strip parentheses before the MemberSelectTree check. Add positive coverage for (String.class) and negative coverage for (Local.class).
There was a problem hiding this comment.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
Fixes apache#2128. A class literal denotes a type with a canonical name unless the type (or an array's element type) is local or a member of a local class. Handle this in LibraryModelsHandler, both for expression checks and for dataflow. Invocations on non-literal receivers stay @nullable.
4ab216e to
78be1a6
Compare
msridhar
left a comment
There was a problem hiding this comment.
This LGTM! I think it's simple enough that we don't need a separate handler and this strategy is the right one. Just address the coderabbit feedback and then we should be good to go.
| private static boolean isCanonicalNameOfClassLiteral( | ||
| MethodInvocationTree invocation, Symbol.MethodSymbol callee, VisitorState state) { | ||
| if (!callee.name.contentEquals("getCanonicalName") | ||
| || !(ASTHelpers.getReceiver(invocation) instanceof MemberSelectTree literal) |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2190 +/- ##
============================================
+ Coverage 89.52% 89.54% +0.02%
- Complexity 4019 4029 +10
============================================
Files 113 113
Lines 13179 13192 +13
Branches 2724 2730 +6
============================================
+ Hits 11798 11813 +15
+ Misses 622 621 -1
+ Partials 759 758 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@vitinh0z do you have cycles to address the coderabbit feedback here? |
Fixes #2128.
A class literal denotes a type with a canonical name unless the type (or an array's element type) is local or a member of a local class (JLS 6.7; anonymous classes have no class literal). In that case
Class#getCanonicalName()can never returnnull, so the@Nullablereturn from the JSpecify JDK model does not apply.Following the suggestion in the issue, this adds the logic to
LibraryModelsHandlerrather than a separate handler. A helper,isCanonicalNameOfClassLiteral, is used both inonOverrideMayBeNullExpr(dereferences, returns, arguments) and inonDataflowVisitMethodInvocation(FORCE_NONNULL, so the result stays non-null through local variables). Invocations on receivers that are not class literals, such asclazz.getCanonicalName()orobj.getClass().getCanonicalName(), remain@Nullable.The new test covers:
void, and array class literals, including via a local variable, a return, and an argument@Nullable: local classes, records, enums and interfaces, a member of a local class, an array of a local class, and a local class inside a lambda@Nullable: parameter, field,getClass()and local-variable receiversI used Claude Code to analyze the codebase and draft an implementation plan, to write the regression test, and to draft the helper's Javadoc and a fix for a NullAway self-check error. I wired the helper into the handler myself, reviewed every change, ran
./gradlew :nullaway:testand./gradlew :nullaway:buildWithNullAwaylocally, and I understand all the changes in this PR.Assisted-by: Claude Code (claude-sonnet-5-5, claude-opus-5-5)