Skip to content

[java] ExceptionAsFlowControl: False negative when the lambda is invoked by the method it is passed to #7117

Closed

Description

@Eljees

ExceptionAsFlowControl no longer reports a throw inside a lambda body. That fixed the false positive of #4815, but it also stopped reporting the case where the lambda is invoked by the method it is passed to.

From spring-framework's LeakAwareNettyDataBufferFactory#checkForLeaks (v5.3.13, lines 50-68, source):

try {
    this.created.forEach(info -> {
        if (((PooledDataBuffer) info.getDataBuffer()).isAllocated()) {
            throw info.getError();
        }
    });
    break;
}
catch (AssertionError ex) {
    ...
}

Iterable.forEach calls the lambda it is passed and relays an exception thrown by it to the caller, so that throw is caught by the catch right below it - the control flow this rule is about.

Reproduced on main (7.29.0-SNAPSHOT, ef27e2a): the rule reports nothing on that file, and the same code as a rule test fixture fails with Expected 1 problem(s), 0 problem(s) found.

Raised by @UncleOwen in the review of #7105; @zbynek suggested that all methods of Stream that take a lambda should be treated the same.

A fix would keep the walk going through a lambda that is an argument of a call whose method calls that argument (Iterable.forEach, Iterator.forEachRemaining, Map.forEach, Optional.ifPresent/ifPresentOrElse, and the Stream methods that take a lambda argument), and leave every other lambda opaque, so that #4815 does not come back.

Activity

  1. changed the title [-][java] ExceptionAsFlowControl: false negative when the lambda runs in the calling thread[/-] [+][java] ExceptionAsFlowControl: false negative when the lambda is invoked by the method it is passed to[/+] on Sep 28, 2026
  2. added this to the 7.29.0 milestone on Sep 30, 2026
  3. changed the title [-][java] ExceptionAsFlowControl: false negative when the lambda is invoked by the method it is passed to[/-] [+][java] ExceptionAsFlowControl: False negative when the lambda is invoked by the method it is passed to[/+] on Oct 29, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions