Java: update to only find 'finalize' calls and add 'super.finalize' exclusion

This commit is contained in:
Jami Cogswell
2025-03-20 08:58:48 -04:00
parent 56ea9b6523
commit 9a6e241f54
10 changed files with 65 additions and 76 deletions

View File

@@ -0,0 +1 @@
| Test.java:3:9:3:23 | finalize(...) | Call to 'finalize'. |

View File

@@ -0,0 +1 @@
Violations of Best Practice/Undesirable Calls/DoNotUseFinalize.ql

View File

@@ -0,0 +1,9 @@
public class Test {
void f() throws Throwable {
this.finalize(); // NON_COMPLIANT
}
void f1() throws Throwable {
f(); // COMPLIANT
}
}

View File

@@ -1,3 +0,0 @@
| Test.java:3:9:3:19 | gc(...) | Call to prohibited method that may modify the JVM's garbage collection process. |
| Test.java:4:9:4:33 | gc(...) | Call to prohibited method that may modify the JVM's garbage collection process. |
| Test.java:5:9:5:23 | finalize(...) | Call to prohibited method that may modify the JVM's garbage collection process. |

View File

@@ -1 +0,0 @@
rules/J-FIN-002/DoNotUseFinalizers.ql

View File

@@ -1,13 +0,0 @@
public class Test {
void f() throws Throwable {
System.gc(); // NON_COMPLIANT
Runtime.getRuntime().gc(); // NON_COMPLIANT
this.finalize(); // NON_COMPLIANT
// this is removed in Java 11
//System.runFinalizersOnExit(true); // NON_COMPLIANT
}
void f1() throws Throwable {
f(); // COMPLIANT
}
}