mirror of
https://github.com/github/codeql.git
synced 2026-04-28 02:05:14 +02:00
Merge pull request #19075 from jcogs33/jcogs33/java/do-not-use-finalizers
Java: Add new quality query to detect `finalize` calls
This commit is contained in:
@@ -0,0 +1 @@
|
||||
| Test.java:4:9:4:23 | finalize(...) | Call to 'finalize()'. |
|
||||
@@ -0,0 +1,2 @@
|
||||
query: Violations of Best Practice/Undesirable Calls/DoNotCallFinalize.ql
|
||||
postprocess: utils/test/InlineExpectationsTestQuery.ql
|
||||
28
java/ql/test/query-tests/DoNotCallFinalize/Test.java
Normal file
28
java/ql/test/query-tests/DoNotCallFinalize/Test.java
Normal file
@@ -0,0 +1,28 @@
|
||||
public class Test {
|
||||
void f() throws Throwable {
|
||||
// NON_COMPLIANT
|
||||
this.finalize(); // $ Alert
|
||||
}
|
||||
|
||||
void f1() throws Throwable {
|
||||
f(); // COMPLIANT
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
// COMPLIANT: If a subclass overrides `finalize()`
|
||||
// it must invoke the superclass finalizer explicitly.
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
// Overload of `finalize`
|
||||
protected void finalize(String s) throws Throwable {
|
||||
// ...
|
||||
}
|
||||
|
||||
void f2() throws Throwable {
|
||||
// COMPLIANT: call to overload of `finalize`
|
||||
this.finalize("overload");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user