Affects PMD Version:
6.22.0
Rule:
AvoidCallingFinalize
Description:
AvoidCallingFinalize detects some false positives, some are not even method calls.
This rule is implemented in pmd-java-6.22.0-sources.jar!\net\sourceforge\pmd\lang\java\rule\errorprone\AvoidCallingFinalizeRule.java,
The following piece of code is used to detect the call of finalize():
private boolean checkForViolation(ScopedNode node) {
MethodScope meth = node.getScope().getEnclosingScope(MethodScope.class);
if (meth != null && "finalize".equals(meth.getName())) {
return false;
}
if (meth != null && checked.contains(meth)) {
return false;
}
if (meth != null) {
checked.add(meth);
}
return true;
}
This code is to find calling of finalize() by name, which causes some false positives to be detected
Code Sample demonstrating the issue:
Example 1:
public boolean finalCommand()
{
return finalize; // This line is marked as an error
}
Example 2:
public LispCommand(boolean finalCommand, SourceLayout layout)
{
this.finalize = finalCommand; // This line is marked as an error
this.layout = layout;
}
Example 3:
_coloringMethod.finalize(raster); // This line is marked as an error
Expected outcome:
false-positive
Running PMD through:
CLI
Affects PMD Version:
6.22.0
Rule:
AvoidCallingFinalize
Description:
AvoidCallingFinalize detects some false positives, some are not even method calls.
This rule is implemented in pmd-java-6.22.0-sources.jar!\net\sourceforge\pmd\lang\java\rule\errorprone\AvoidCallingFinalizeRule.java,
The following piece of code is used to detect the call of finalize():
This code is to find calling of
finalize()by name, which causes some false positives to be detectedCode Sample demonstrating the issue:
Example 1:
Example 2:
Example 3:
Expected outcome:
false-positive
Running PMD through:
CLI