GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] AvoidCallingFinalize detects some false positives · Issue #2578 · pmd/pmd

[java] AvoidCallingFinalize detects some false positives #2578

New issue
Copy link
New issue
Copy link
Closed
#2643
Closed
[java] AvoidCallingFinalize detects some false positives#2578
#2643
Copy link
Labels
a:false-positivePMD flags a piece of code that is not problematic
Milestone
6.26.0

Description

@wuchiuwong
wuchiuwong
opened on Jun 14, 2020
Issue body actions

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

Activity

  1. wuchiuwong
    added
    a:bugPMD crashes or fails to analyse a file.
    on Jun 14, 2020
  2. adangel
    changed the title [-][java]AvoidCallingFinalize detects some false positives[/-] [+][java] AvoidCallingFinalize detects some false positives[/+] on Jul 16, 2020
  3. adangel
    added
    a:false-positivePMD flags a piece of code that is not problematic
    and removed
    a:bugPMD crashes or fails to analyse a file.
    on Jul 16, 2020
  4. jsotuyod
    added
    has:pr
    on Jul 17, 2020
  5. jsotuyod
    added this to the 6.26.0 milestone on Jul 17, 2020
  6. adangel
    closed this as completedin 6b69964on Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type

    Projects

    No projects

      Milestone

      • 6.26.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.