-
Notifications
You must be signed in to change notification settings - Fork 293
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
Fix bugs in reading varargs annotations from bytecodes #1055
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1055 +/- ##
============================================
- Coverage 87.61% 87.60% -0.02%
- Complexity 2183 2203 +20
============================================
Files 85 85
Lines 7161 7187 +26
Branches 1404 1415 +11
============================================
+ Hits 6274 6296 +22
- Misses 453 456 +3
- Partials 434 435 +1 ☔ View full report in Codecov by Sentry. |
Found another bug, will try to fix it as part of this PR |
Now ready for review again 🙂 |
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.
Some nits, but overall LGTM
@@ -47,4 +47,24 @@ public void methodReferenceOnNullableVariable() { | |||
"}") | |||
.doTest(); | |||
} | |||
|
|||
@Test | |||
public void testNullableLambdaParamTypeUse() { |
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.
Do we have the true positive case test somewhere? E.g. something showing that:
NonNullParamFunctionTypeUse n3 = (@Nullable Object x) -> (x == null) ? \"null\" : x.toString();",
Fails if NonNullParamFunctionTypeUse
is equivalent to NonNullParamFunctionTypeUse
but without @Nullable
on takeVal
.
Also, how about assigning a lambda that doesn't check for null?
Feel free to ignore if these tests already exist somewhere (they well might), just checking since this test below implies those cases too.
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.
I think those tests exist here:
https://github.com/uber/NullAway/blob/master/nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayJava8NegativeCases.java
https://github.com/uber/NullAway/blob/master/nullaway/src/test/resources/com/uber/nullaway/testdata/NullAwayJava8PositiveCases.java
The key difference in the new unit test is that @Nullable
is a type-use annotation rather than a declaration annotation, and with our new logic we initially weren't reading it out correctly. I added a comment in a59a7a8
"public class Test {", | ||
" public void testDeclaration() {", | ||
" String x = null;", | ||
" Varargs s = new Varargs(x);", |
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.
Can we add the case passing new Varargs(x, y)
where x
is non-null but y
is @Nullable
?
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.
" String[] y = null;", | ||
" // BUG: Diagnostic contains: passing @Nullable parameter 'x'", | ||
" RestrictivelyAnnotatedVarargs.test(x);", | ||
" RestrictivelyAnnotatedVarargs.test(y);", |
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.
Is there a way to annotate varargs as non-null array of non-null elements? Do we want a test case for that? (separate from RestrictivelyAnnotatedVarargs.test
)
I'd even argue that it is exceedingly rare for the intention of a varargs argument to be "a potentially nullable array of non-null elements", but I guess we should follow JSpecify here either way.
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.
switch (position.type) { | ||
case METHOD_FORMAL_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.
If we care only about one case, why is this a switch and not an if
?
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.
For the case of declaration annotations, we were using
Flags.VARARGS
to check if aSymbol
represented a varargs parameter, but this only works if the method is defined in source code. We add new methods for varargs parameters that may be defined in bytecodes, and always check for declaration annotations in such cases.For type use annotations on parameters, for a method from bytecodes the annotation info is stored on the method's symbol, not the parameter's. We borrow some Error Prone code to handle this case.