-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Java: Add new quality query to detect finalize
calls
#19075
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
815802f
to
90653ed
Compare
1674c8d
to
ed22a16
Compare
@knewbury01 for awareness |
java/ql/src/Violations of Best Practice/Undesirable Calls/DoNotCallFinalize.md
Outdated
Show resolved
Hide resolved
java/ql/src/Violations of Best Practice/Undesirable Calls/DoNotCallFinalize.ql
Outdated
Show resolved
Hide resolved
Co-authored-by: Owen Mansel-Chan <62447351+owen-mc@users.noreply.github.com>
java/ql/src/Violations of Best Practice/Undesirable Calls/DoNotCallFinalize.md
Outdated
Show resolved
Hide resolved
@jcogs33 Thanks for writing up this PR ✨ The docs team will look this over and review it within the next couple of days |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcogs33 - Approving on behalf of Docs 👍🏻
Just a minor suggestion that you can ignore if you don't agree 😅
@@ -0,0 +1,59 @@ | |||
## Overview | |||
|
|||
Triggering garbage collection by directly calling `finalize()` may either have no effect or may trigger unnecessary garbage collection, leading to erratic behavior, performance issues, or deadlock. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can simplify here
Triggering garbage collection by directly calling `finalize()` may either have no effect or may trigger unnecessary garbage collection, leading to erratic behavior, performance issues, or deadlock. | |
Triggering garbage collection by directly calling `finalize()` may either have no effect or trigger unnecessary garbage collection, leading to erratic behavior, performance issues, or deadlock. |
Description
Adds a new quality query to detect
finalize
calls. This query is migrated from the advance security team's quality queries.Consideration
Changes from original query. Let me know if you disagree with any of these changes:
finalize
calls now. Alerts forrunFinalizersOnExit
andgc
will continue to be reported on the pre-existing queriesjava/run-finalizers-on-exit
andjava/garbage-collection
, respectively. I will make follow-up PRs updating these pre-existing queries if needed.super.finalize
calls that occur within a callable that overridesfinalize
since the Java doc forfinalize
states: "If a subclass overridesfinalize
it must invoke the superclass finalizer explicitly", and alerting on these calls would contradict our pre-existingjava/missing-super-finalize
query. This exclusion reduces the number of alerts on the MRVA top-100 from 66 to 24 and on the MRVA top-1000 from 954 to 115.finalize
. My understanding is that the JVM will not call overloads of finalize when handling garbage collection, but will only callfinalize()
and overrides offinalize()
. So I don't think overloads are relevant for alerts. Let me know if you disagree. This exclusion further reduces the number of alerts on the MRVA top-100 from 24 to 5 and on the MRVA top-1000 from 115 to 40.Other Notes:
finalize
call then attempts to useAutoCloseable
as suggested in the QHelp.