-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Java: Add new quality query to detect finalize calls
#19075
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 |
mchammer01
left a comment
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 😅
java/ql/src/Violations of Best Practice/Undesirable Calls/DoNotCallFinalize.md
Outdated
Show resolved
Hide resolved
Co-authored-by: mc <42146119+mchammer01@users.noreply.github.com>
|
Thanks @mchammer01! I've applied your suggestion. 🙇 |
Description
Adds a new quality query to detect
finalizecalls. 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:
finalizecalls now. Alerts forrunFinalizersOnExitandgcwill continue to be reported on the pre-existing queriesjava/run-finalizers-on-exitandjava/garbage-collection, respectively. I will make follow-up PRs updating these pre-existing queries if needed.super.finalizecalls that occur within a callable that overridesfinalizesince the Java doc forfinalizestates: "If a subclass overridesfinalizeit must invoke the superclass finalizer explicitly", and alerting on these calls would contradict our pre-existingjava/missing-super-finalizequery. 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:
finalizecall then attempts to useAutoCloseableas suggested in the QHelp.