A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/2578 below:

[java] AvoidCallingFinalize detects some false positives · Issue #2578 · pmd/pmd · GitHub

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4