Java: Add new quality query to detect finalize
calls
#19075
Draft
+94
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: