File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
main/java/com/google/errorprone/bugpatterns/nullness
test/java/com/google/errorprone/bugpatterns/nullness Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change 31
31
import static com .google .errorprone .matchers .Matchers .anyMethod ;
32
32
import static com .google .errorprone .matchers .Matchers .anyOf ;
33
33
import static com .google .errorprone .matchers .Matchers .expressionStatement ;
34
+ import static com .google .errorprone .matchers .Matchers .instanceMethod ;
34
35
import static com .google .errorprone .matchers .Matchers .staticMethod ;
35
36
import static com .google .errorprone .util .ASTHelpers .constValue ;
36
37
import static com .google .errorprone .util .ASTHelpers .findEnclosingMethod ;
@@ -107,6 +108,7 @@ public class ReturnMissingNullable extends BugChecker implements CompilationUnit
107
108
*/
108
109
.onDescendantOfAny ("org.junit.Assert" , "junit.framework.Assert" )
109
110
.named ("fail" ),
111
+ instanceMethod ().onDescendantOf ("java.lang.Runtime" ).namedAnyOf ("exit" , "halt" ),
110
112
staticMethod ().onClass ("java.lang.System" ).named ("exit" )));
111
113
112
114
private static final Matcher <StatementTree > FAILS_IF_PASSED_FALSE =
Original file line number Diff line number Diff line change @@ -1498,6 +1498,40 @@ public String getMessage() {
1498
1498
.doTest ();
1499
1499
}
1500
1500
1501
+ @ Test
1502
+ public void negativeCases_unreachableRuntimeExit () {
1503
+ createCompilationTestHelper ()
1504
+ .addSourceLines (
1505
+ "com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
1506
+ """
1507
+ package com.google.errorprone.bugpatterns.nullness;
1508
+ class LiteralNullReturnTest {
1509
+ public String getMessage() {
1510
+ Runtime.getRuntime().exit(1);
1511
+ return null;
1512
+ }
1513
+ }
1514
+ """ )
1515
+ .doTest ();
1516
+ }
1517
+
1518
+ @ Test
1519
+ public void negativeCases_unreachableRuntimeHalt () {
1520
+ createCompilationTestHelper ()
1521
+ .addSourceLines (
1522
+ "com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
1523
+ """
1524
+ package com.google.errorprone.bugpatterns.nullness;
1525
+ class LiteralNullReturnTest {
1526
+ public String getMessage() {
1527
+ Runtime.getRuntime().halt(1);
1528
+ return null;
1529
+ }
1530
+ }
1531
+ """ )
1532
+ .doTest ();
1533
+ }
1534
+
1501
1535
@ Test
1502
1536
public void negativeCases_unreachableAssertFail () {
1503
1537
createCompilationTestHelper ()
You can’t perform that action at this time.
0 commit comments