Skip to content

[java] Fix for ReturnFromFinallyBlock false-positives - #1503

Merged
adangel merged 3 commits into
pmd:masterfrom
rishabhdeepsingh:fun
Dec 13, 2018
Merged

adangel merged 3 commits into
pmd:masterfrom
rishabhdeepsingh:fun

Conversation

@rishabhdeepsingh

@rishabhdeepsingh rishabhdeepsingh commented Dec 4, 2018 •

Copy link
Copy Markdown
Contributor

Before submitting a PR, please check that:

  • The PR is submitted against master. The PMD team will merge back to support branches as needed.
  • ./mvnw clean verify passes. This will build and test PMD, execute PMD and checkstyle rules. Check this for more info

PR Description:
ReturnFromFinallyBlock was giving wrong results for Lambdas or Class return statements.
Added new Tests also.

Fixes #1035

@jsotuyod jsotuyod changed the title [java] Issue pmd#1035: ReturnFromFinallyBlock false-positives. [java] Fix for ReturnFromFinallyBlock false-positives Dec 4, 2018
@ghost

ghost commented Dec 4, 2018 •

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

Generated by 🚫 Danger

@adangel adangel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your pull request!
You fix looks fine 👍
Just have a look at my comments on the test cases.

@jsotuyod

jsotuyod commented Dec 9, 2018 •

Copy link
Copy Markdown
Member

I'd personally also add 2 test cases:

  1. with an anonymous class instead of a lambda
  2. with a local class

ie:

public class Foo {
    void printSomething() {
        try {
            System.out.println("Integers: ");
        } finally {
            Arrays.asList(0, 1, 2).map(new Function<Integer, Integer>() {
               @Override
               public Integer apply(Integer i) {
                   return i + 1;
               }
           }).forEach(i -> System.out.println(i));
        }
    }
}
public class Foo {
    void printSomething() {
        try {
            System.out.println("Integers: ");
        } finally {
            class Incrementer implements Function<Integer, Integer> {
               @Override
               public Integer apply(Integer i) {
                   return i + 1;
               }
            }
            Arrays.asList(0, 1, 2).map(new Incrementer()).forEach(i -> System.out.println(i));
        }
    }
}

EDIT: This second case seems to already be addressed, I missed it on my first check

@adangel adangel added the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label Dec 10, 2018
@jsotuyod jsotuyod removed the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label Dec 12, 2018
@adangel adangel added this to the 6.11.0 milestone Dec 13, 2018
@adangel adangel self-assigned this Dec 13, 2018
@adangel
adangel merged commit bb0cb91 into pmd:master Dec 13, 2018
adangel added a commit that referenced this pull request Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] ReturnFromFinallyBlock: False positive on lambda expression in finally block

3 participants