Skip to content

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

Closed

Description

@lgoldstein

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"

Activity

  1. changed the title [-][java] PMD false error on lambda expression in 'finally' block[/-] [+][java] ReturnFromFinallyBlock: False positive on lambda expression in finally block[/+] on Apr 19, 2018
  2. added
    a:bug
    a:false-positive
    on Apr 19, 2018
  3. adangel commented on Apr 19, 2018

    @adangel
    Member

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

  4. added
    good first issue
    on Apr 19, 2018
  5. added
    in:xpath
    and removed on May 19, 2018
  6. added this to the 6.11.0 milestone on Dec 13, 2018
  7. added a commit that references this issue on Dec 13, 2018
    89f23f7
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:buga:false-positivegood first issuein:xpath

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions