-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSpecify: handle incorrect method parameter nullability for method reference #845
Changes from 1 commit
0b49a42
06d157f
77c7c4f
7c891d3
6f4505c
3f5c6cf
6092a56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -429,8 +429,7 @@ public void testForMethodReferenceInAnAssignment() { | |
" return o.toString();", | ||
" }", | ||
" static void testPositive() {", | ||
" // TODO: we should report an error here, since Test::foo cannot take", | ||
" // a @Nullable parameter. we don't catch this yet", | ||
" // BUG: Diagnostic contains: referenced method is @NonNull", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now, the full error message we emit here is:
It'd be nice if we could find a way to print the functional interface method type so it refers to the annotated type arguments rather than the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree, I'll try and find a way to do that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After further investigation getting better error messages needs more thought. I'll file a follow-up issue but let's not hold up this PR on this. |
||
" A<@Nullable Object> p = Test::foo;", | ||
" }", | ||
" static void testNegative() {", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool that this works! But it's a bit unclean to pass in a
MemberReferenceTree
directly. Instead, how about we have a parameter@Nullable Type enclosingType
, and at the caller you pass in the type of theMemberReferenceTree
if the tree is non-null. Then in this method, ifenclosingType == null
, we set it to begetTypeForSymbol(enclosingSymbol, state)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will also need to update the Javadoc for this method to document the new parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I have a better idea. Just below this method (line 909), there is another overload of
getGenericMethodParameterNullness()
that takes aType
rather than aSymbol
. How about we not modify this method, and instead at the call site just invoke the other method if we have aMemberReferenceTree
? Right now we'll have to do a null check on theType
at the caller, but I am also open to making the parameter of the other method@Nullable
and doing the check there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we have a MemberReferenceTree!=null, it's type will also not be null right? if I understand correctly is this what you're suggesting?, the place where we call the method from NullAway.java (line 734) to be something like:
This does make that line very complicated but then we don't have to change any method signatures. Maybe I misunderstood and what you're suggesting is even simpler