mirror of
https://github.com/github/codeql.git
synced 2026-04-23 15:55:18 +02:00
Java: Fix java/jvm-exit false positives for local nested classes in test methods
This commit is contained in:
@@ -63,7 +63,15 @@ class SourceMethodNotMainOrTest extends Method {
|
||||
this.fromSource() and
|
||||
not this instanceof MainMethod and
|
||||
not this instanceof LikelyTestMethod and
|
||||
not this.getEnclosingCallable() instanceof LikelyTestMethod
|
||||
not (
|
||||
this.getEnclosingCallable*() instanceof LikelyTestMethod
|
||||
or
|
||||
this.getDeclaringType()
|
||||
.getEnclosingType*()
|
||||
.(LocalClassOrInterface)
|
||||
.getLocalTypeDeclStmt()
|
||||
.getEnclosingCallable() instanceof LikelyTestMethod
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,3 @@
|
||||
| ExampleRuntimeHalt.java:21:17:21:44 | halt(...) | Avoid calls to Runtime.halt() as this prevents runtime cleanup and makes code harder to reuse. |
|
||||
| ExampleSystemExit.java:22:17:22:30 | exit(...) | Avoid calls to System.exit() as this prevents runtime cleanup and makes code harder to reuse. |
|
||||
| ExampleSystemExit.java:25:17:25:30 | exit(...) | Avoid calls to System.exit() as this prevents runtime cleanup and makes code harder to reuse. |
|
||||
| LocalClassInTestMethod.java:7:25:7:38 | exit(...) | Avoid calls to System.exit() as this prevents runtime cleanup and makes code harder to reuse. |
|
||||
| LocalClassInTestMethod.java:8:25:8:52 | halt(...) | Avoid calls to Runtime.halt() as this prevents runtime cleanup and makes code harder to reuse. |
|
||||
| LocalClassInTestMethod.java:20:21:20:34 | exit(...) | Avoid calls to System.exit() as this prevents runtime cleanup and makes code harder to reuse. |
|
||||
| LocalClassInTestMethod.java:21:21:21:48 | halt(...) | Avoid calls to Runtime.halt() as this prevents runtime cleanup and makes code harder to reuse. |
|
||||
|
||||
@@ -4,8 +4,8 @@ public class LocalClassInTestMethod {
|
||||
void func() {
|
||||
class NestedLocalClass {
|
||||
void nestedMethod() {
|
||||
System.exit(4); // $ SPURIOUS: Alert
|
||||
Runtime.getRuntime().halt(5); // $ SPURIOUS: Alert
|
||||
System.exit(4);
|
||||
Runtime.getRuntime().halt(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,8 +17,8 @@ public class LocalClassInTestMethod {
|
||||
class OuterLocalClass {
|
||||
class NestedLocalClass {
|
||||
void nestedMethod() {
|
||||
System.exit(4); // $ SPURIOUS: Alert
|
||||
Runtime.getRuntime().halt(5); // $ SPURIOUS: Alert
|
||||
System.exit(4);
|
||||
Runtime.getRuntime().halt(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user