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 (2578) by Drofff · Pull Request #2643 · pmd/pmd

Conversation

@Drofff

@Drofff Drofff commented Jul 15, 2020

Copy link
Copy Markdown
Contributor

Describe the PR

I have modified the AvoidCallingFinalizeRule class to fix false positives when variables with name 'finalize' and finalize methods with args are detected as a problem. Also I've added 2 tests validating that the false positive bugs were fixed.

Related issues

  • Fixes [java] AvoidCallingFinalize detects some false positives #2578

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by travis)
  • Added (in-code) documentation (if needed)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Drofff
[java]AvoidCallingFinalize detects some false positives (2578)
5a6e3d6
@ghost

ghost commented Jul 15, 2020 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
1 Message
📖 This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 1 violations, 0 errors and 2 configuration errors.
Full report
✅ This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 1 violations, 0 errors and 2 configuration errors.
Full report
✅ This changeset introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 2 violations, 0 errors and 2 configuration errors.
Full report
✅ This changeset introduces 5 new violations, 0 new errors and 0 new configuration errors,
removes 5 violations, 0 errors and 2 configuration errors.
Full report

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rsoesemann rsoesemann modified the milestone: 6.26.0 Jul 15, 2020
jsotuyod
jsotuyod reviewed Jul 15, 2020
View reviewed changes

@jsotuyod jsotuyod left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Drofff thanks for the contribution! Glad to get new devs onboard!

One thing I do notice is that you are now reporting the violation on the block node. This has 2 consequences:

  1. It's harder for the developer to find the violation, ie:
if (foo) { // <-- violation reported here
  bar();
  // do stuff
  finalize(); // <-- actual illegal invocation is way down here
  //maybe more code…
}
  1. if a single block has more than 1 finalize invocation, they all get reported on the same line, so the developer sees several identical violations on the same line
if (foo) { // <-- 2 violations reported here
  bar.finalize(); // <-- actual illegal invocation 1 is here
  // do stuff
  finalize(); // <-- actual illegal invocation 2 is here
  //maybe more code…
}

I'd try and call addViolation on the node that corresponds to the actual invocation.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...va/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidCallingFinalizeRule.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Drofff
AvoidCallingFinalize: addViolation, getArgsCount fix
2eedff0
@Drofff

Drofff commented Jul 16, 2020

Copy link
Copy Markdown
Contributor Author

@jsotuyod thank you for your time and clear explanation! I've changed the code to use addViolation on the proper node and have fixed getArgsCount method mistake (I hope so ☺️ ) in commit 2eedff0. Would you be able to review the changes?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jsotuyod

jsotuyod commented Jul 16, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@Drofff awesome! thanks for the quick response!

The only thing I'm seeing is that the regression tester says we seem to have introduced a false negative now…

The report says we removed a FP (yay! 🎉 ) but are also no longer reporting this super.finalize() call here. Would you add a test case for this super call in constructor and see if you can reproduce and fix it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel changed the title [java]AvoidCallingFinalize detects some false positives (2578) [java] AvoidCallingFinalize detects some false positives (2578) Jul 16, 2020
@Drofff
AvoidCallingFinalize: constructor false negative fix
9bbb6aa
adangel
adangel reviewed Jul 16, 2020
View reviewed changes
Comment thread ...rc/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidCallingFinalize.xml Resolved

Uh oh!

There was an error while loading. Please reload this page.

@Drofff
AvoidCallingFinalize: expected lines added to test
01e48c8
@jsotuyod jsotuyod added this to the 6.26.0 milestone Jul 17, 2020
adangel
adangel approved these changes Jul 17, 2020
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!
I'll change the rule to use the rulechain when merging.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...va/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidCallingFinalizeRule.java
if (isIncorrectFinalizeMethodCall(primaryExpression)) {
addViolation(data, primaryExpression);
}
return data;

@adangel adangel Jul 17, 2020

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fully correct, we need to call here either super or need to use the rule chain. A primary expression could define a anonymous class, which in turn could have primary expressions which call the finalize method....

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
adangel added a commit that referenced this pull request Jul 17, 2020
@adangel
[doc] Update release notes, refs #2643, fixes #2578
6b69964
adangel added a commit that referenced this pull request Jul 17, 2020
@adangel
Merge branch 'pr-2643'
25405eb
[java] AvoidCallingFinalize detects some false positives (2578) #2643
@adangel
adangel merged commit 01e48c8 into pmd:master Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jsotuyod jsotuyod jsotuyod left review comments
@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

6.26.0

Development

Successfully merging this pull request may close these issues.

[java] AvoidCallingFinalize detects some false positives

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@Drofff @jsotuyod @adangel @rsoesemann
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.
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.