File tree 2 files changed +24
-11
lines changed
main/java/com/google/errorprone/bugpatterns/nullness
test/java/com/google/errorprone/bugpatterns/nullness 2 files changed +24
-11
lines changed Original file line number Diff line number Diff line change @@ -84,17 +84,14 @@ public class ReturnMissingNullable extends BugChecker implements CompilationUnit
84
84
anyOf (
85
85
anyMethod ().anyClass ().withNameMatching (compile ("throw.*Exception" )),
86
86
staticMethod ()
87
- .onClassAny (
88
- "org.junit.Assert" ,
89
- "junit.framework.Assert" ,
90
- /*
91
- * I'm not sure if TestCase is necessary, as it doesn't define its own fail()
92
- * method, but it commonly appears in lists like this one, so I've included
93
- * it. (Maybe the method was defined on TestCase many versions ago?)
94
- *
95
- * TODO(cpovirk): Confirm need, or remove from everywhere.
96
- */
97
- "junit.framework.TestCase" )
87
+ /*
88
+ * b/285157761: The reason to look at descendants of the listed classes is mostly
89
+ * to catch non-canonical static imports: While TestCase doesn't define its own
90
+ * fail() method, javac still lets users import it with "import static
91
+ * junit.framework.TestCase.fail." And when users do that, javac acts as if fail()
92
+ * is a member of TestCase. We still want to cover it here.
93
+ */
94
+ .onDescendantOfAny ("org.junit.Assert" , "junit.framework.Assert" )
98
95
.named ("fail" ),
99
96
staticMethod ().onClass ("java.lang.System" ).named ("exit" )));
100
97
Original file line number Diff line number Diff line change @@ -1389,6 +1389,22 @@ public void negativeCases_unreachableFail() {
1389
1389
.doTest ();
1390
1390
}
1391
1391
1392
+ @ Test
1393
+ public void negativeCases_unreachableFailNonCanonicalImport () {
1394
+ createCompilationTestHelper ()
1395
+ .addSourceLines (
1396
+ "com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
1397
+ "package com.google.errorprone.bugpatterns.nullness;" ,
1398
+ "import static junit.framework.TestCase.fail;" ,
1399
+ "class LiteralNullReturnTest {" ,
1400
+ " public String getMessage() {" ,
1401
+ " fail();" ,
1402
+ " return null;" ,
1403
+ " }" ,
1404
+ "}" )
1405
+ .doTest ();
1406
+ }
1407
+
1392
1408
@ Test
1393
1409
public void negativeCases_unreachableThrowExceptionMethod () {
1394
1410
createCompilationTestHelper ()
You can’t perform that action at this time.
0 commit comments