GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||
GeezerVison is showing github.com — [java] Fix #4815: ExceptionAsFlowControl: stop at a lambda body by Eljees · Pull Request #7105 · pmd/pmd Conversation
Contributor
Describe the PR
try { es.execute(() -> { try { unsafeDoPublish(details); } catch (IOException e) { throw new UncheckedIOException(e); } }); } catch (RuntimeException e) { LOGGER.warn("Issue publishing notification " + details, e); } the The rule already stops at a body declaration, which covers anonymous and local classes. This makes it stop at a lambda too: whoever invokes the lambda is not visible from the throw site, so the rule cannot tell whether a surrounding TestsTwo cases in
Related issuesReady?
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsAn exception thrown in a lambda body propagates to whoever invokes the lambda, not to the try statement around the lambda expression. Fixes pmd#4815
|
There was an error while loading. Please reload this page.
|
Compared to main: (comment created at 2026-09-26 09:33:55+00:00 for 817461b) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This could be considered a new false-negative.
I'll still merge this, because it's definitely an improvement.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I looked into the false negative you pointed at. It reproduces on the merged rule: on Filed #7117 with a fix that keeps the walk going through lambdas passed to the JDK methods whose contract says the action runs in the calling thread; every other lambda stays opaque. #7118 is the PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…hod it is passed to pmd#7105 stopped the walk at every lambda body. That fixed the false positive of pmd#4815, but it also stopped reporting a throw inside a lambda that the method it is passed to calls itself. spring-framework's LeakAwareNettyDataBufferFactory#checkForLeaks (v5.3.13, line 56) throws inside Iterable.forEach and catches the exception right below. The walk now continues 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. A terminal operation calls the action while the call is evaluated; an intermediate operation is evaluated by the terminal operation of the same pipeline. Every other lambda stays opaque, so pmd#4815 does not come back. Signed-off-by: Eljees <[email protected]>
…hod it is passed to (#7118) * [java] ExceptionAsFlowControl: a throw in a lambda invoked by the method it is passed to #7105 stopped the walk at every lambda body. That fixed the false positive of #4815, but it also stopped reporting a throw inside a lambda that the method it is passed to calls itself. spring-framework's LeakAwareNettyDataBufferFactory#checkForLeaks (v5.3.13, line 56) throws inside Iterable.forEach and catches the exception right below. The walk now continues 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. A terminal operation calls the action while the call is evaluated; an intermediate operation is evaluated by the terminal operation of the same pipeline. Every other lambda stays opaque, so #4815 does not come back. Signed-off-by: Eljees <[email protected]> * Use compound invocation matcher and clarify release notes * [java] Handle primitive streams in ExceptionAsFlowControl --------- Signed-off-by: Eljees <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[java] ExceptionAsFlowControl: False positive on Lambda/asynchronous
There was an error while loading. Please reload this page.