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] ReturnFromFinallyBlock: False positive on lambda expression in finally block #1035

Closed
lgoldstein opened this issue Apr 11, 2018 · 1 comment · Fixed by #1503
Closed
Labels
a:bug PMD crashes or fails to analyse a file. a:false-positive PMD flags a piece of code that is not problematic good first issue A great starting point for new contributors in:xpath Relating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolution
Milestone

Comments

@lgoldstein
Copy link

Affects PMD Version:
5.6.1

Rule:
ReturnFromFinallyBlock Priority:3 Avoid returning from a finally block

Description:

Code Sample demonstrating the issue:

try {
    ...
} catch (Exception e) {
    ...
} finally {
    Collection<ServiceExecutionEntry> untracked = serviceExecutionTracker.untrackMatchingEntries(e -> {
        ServiceExecutionIdentifiers ids = e.getIdentifiers();
        Long execBqiId = (ids == null) ? null : ids.getBqiId();
        return Objects.equals(bqiId, execBqiId);
    });
    untracked.forEach(e -> logger.info("overwriteLastBqi(bqId={}, bqiId={}) untracked {}", bqId, bqiId, e));
}

Obviously, the code in the finally block does not return - PMD mistakes the return statement in the lambda expression as a return from the finally block

Running PMD through: [Maven]

Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T21:49:05+02:00)
Maven home: /home/lyor/Software/apache-maven-3.5.3
Java version: 1.8.0_162, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.162-3.b12.fc27.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.14-300.fc27.x86_64", arch: "amd64", family: "unix"
@adangel adangel changed the title [java] PMD false error on lambda expression in 'finally' block [java] ReturnFromFinallyBlock: False positive on lambda expression in finally block Apr 19, 2018
@adangel adangel added a:bug PMD crashes or fails to analyse a file. a:false-positive PMD flags a piece of code that is not problematic labels Apr 19, 2018
@adangel
Copy link
Member

adangel commented Apr 19, 2018

Thanks for the report. I can confirm, that it is still present on the latest version.

@adangel adangel added xpath good first issue A great starting point for new contributors labels Apr 19, 2018
@adangel adangel added in:xpath Relating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolution and removed using:xpath labels May 19, 2018
@jsotuyod jsotuyod added the has:pr label Dec 4, 2018
@adangel adangel added this to the 6.11.0 milestone Dec 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug PMD crashes or fails to analyse a file. a:false-positive PMD flags a piece of code that is not problematic good first issue A great starting point for new contributors in:xpath Relating to xpath support at large, eg Jaxen / Saxon, custom functions, attribute resolution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants