Skip to content
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] AvoidCallingFinalize detects some false positives #2578

Closed
wuchiuwong opened this issue Jun 14, 2020 · 0 comments · Fixed by #2643
Closed

[java] AvoidCallingFinalize detects some false positives #2578

wuchiuwong opened this issue Jun 14, 2020 · 0 comments · Fixed by #2643
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@wuchiuwong
Copy link

wuchiuwong commented Jun 14, 2020

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

@wuchiuwong wuchiuwong added the a:bug PMD crashes or fails to analyse a file. label Jun 14, 2020
@adangel adangel changed the title [java]AvoidCallingFinalize detects some false positives [java] AvoidCallingFinalize detects some false positives Jul 16, 2020
@adangel adangel added a:false-positive PMD flags a piece of code that is not problematic and removed a:bug PMD crashes or fails to analyse a file. labels Jul 16, 2020
@jsotuyod jsotuyod added this to the 6.26.0 milestone Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants