-
Notifications
You must be signed in to change notification settings - Fork 295
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
Changes from 18 commits
d700d1a
2ba7a82
e7ea1bf
49652e4
74740fe
6783bce
311618e
d21712b
b9d33b3
989539a
9dcac6b
25ad62a
b38e3cb
270963b
2f7a162
ddb1ab0
ced7613
841ea92
dac889d
a59a7a8
0abca22
f30299a
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 |
---|---|---|
|
@@ -71,6 +71,39 @@ public void testNullableVarargs() { | |
.doTest(); | ||
} | ||
|
||
/** Test for a @Nullable declaration annotation on a varargs parameter defined in bytecode */ | ||
@Test | ||
public void nullableDeclarationVarArgsFromBytecode() { | ||
defaultCompilationHelper | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import com.uber.lib.Varargs;", | ||
"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 commentThe reason will be displayed to describe this comment to others. Learn more. Can we add the case passing 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. |
||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
@Test | ||
public void nullableTypeUseVarArgsFromBytecode() { | ||
defaultCompilationHelper | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import com.uber.lib.Varargs;", | ||
"public class Test {", | ||
" public void testTypeUse() {", | ||
" String[] x = null;", | ||
" Varargs.typeUse(x);", | ||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
|
||
@Test | ||
public void nullableTypeUseVarargs() { | ||
defaultCompilationHelper | ||
|
@@ -515,4 +548,33 @@ public void testVarargsRestrictive() { | |
"}") | ||
.doTest(); | ||
} | ||
|
||
/** | ||
* Test for a restrictive @NonNull declaration annotation on a varargs parameter defined in | ||
* bytecode | ||
*/ | ||
@Test | ||
public void testVarargsRestrictiveBytecodes() { | ||
makeTestHelperWithArgs( | ||
Arrays.asList( | ||
"-d", | ||
temporaryFolder.getRoot().getAbsolutePath(), | ||
"-XepOpt:NullAway:AnnotatedPackages=com.uber", | ||
"-XepOpt:NullAway:UnannotatedSubPackages=com.uber.lib.unannotated", | ||
"-XepOpt:NullAway:AcknowledgeRestrictiveAnnotations=true")) | ||
.addSourceLines( | ||
"Test.java", | ||
"package com.uber;", | ||
"import com.uber.lib.unannotated.RestrictivelyAnnotatedVarargs;", | ||
"public class Test {", | ||
" public void testDeclaration() {", | ||
" String x = null;", | ||
" 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 commentThe 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 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
" }", | ||
"}") | ||
.doTest(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.uber.lib; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
public class Varargs { | ||
|
||
public Varargs(@Nullable String... args) {} | ||
|
||
public static void typeUse(String @org.jspecify.annotations.Nullable ... args) {} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.uber.lib.unannotated; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
public class RestrictivelyAnnotatedVarargs { | ||
|
||
public static void test(@Nonnull String... args) {} | ||
} |
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.
dac889d