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] False negative in UnnecessaryLocalBeforeReturn when splitting statements across multiple lines #1775

Closed
davidburstromspotify opened this issue Apr 14, 2019 · 0 comments · Fixed by #1778
Assignees
Labels
a:false-negative PMD doesn't flag a problematic piece of code has:pr The issue is already tackled in a PR
Milestone

Comments

@davidburstromspotify
Copy link
Contributor

davidburstromspotify commented Apr 14, 2019

Affects PMD Version:
6.13.0

Rule:
UnnecessaryLocalBeforeReturn

Description:
An unnecessary local is missed if chained method calls are split up on separate lines AND the method calls reference another variable.

Code Sample demonstrating the issue:

public class Test {

    public Object test1() {
        int i = 0; // the usage of i seems to be relevant for the false negative
        Object o = thing()
            .make(i);
        return o; // false negative when the chained calls are on separate lines
    }   

    public Object test2() {
        int i = 0;
        Object o = thing().make(i);
        return o; // true positive
    }   

    public Object test3() {
        Object o = thing()
            .make();
        return o; // true positive
    }   

    public Object test4() {
        Object o = thing().make();
        return o; // true positive
    }   
}

Running PMD through:
CLI/Gradle

@jsotuyod jsotuyod changed the title [java] False negative in UnnecessaryLocalBeforeReturn [java] False negative in UnnecessaryLocalBeforeReturn when splitting statements across multiple lines Apr 16, 2019
@jsotuyod jsotuyod added this to the 6.14.0 milestone Apr 16, 2019
@jsotuyod jsotuyod added the a:false-negative PMD doesn't flag a problematic piece of code label Apr 16, 2019
@jsotuyod jsotuyod self-assigned this Apr 16, 2019
jsotuyod added a commit to Monits/pmd that referenced this issue Apr 16, 2019
jsotuyod added a commit to Monits/pmd that referenced this issue Apr 16, 2019
@jsotuyod jsotuyod added the has:pr The issue is already tackled in a PR label Apr 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-negative PMD doesn't flag a problematic piece of code has:pr The issue is already tackled in a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants