Skip to content

[java] ExceptionAsFlowControl: False positive on Lambda/asynchronous #4815

Closed

Description

@blacelle

Affects PMD Version:
7.0.0-rc4

Rule: ExceptionAsFlowControl

Description:
Given rules is a false-positive as the exception in the Lambda would typically not be caught in the outer catch block.

Code Sample demonstrating the issue:

	protected void doPublish(String issueLabel, Map<?, ?> details) {
	        ExecutorService es = ...;
		try {
			es.execute(() -> {
				try {
					unsafeDoPublish(details);
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			});
		} catch (RuntimeException e) {
			// Do not re-throw else it would go directly to the UncaughtExceptionHandler
			LOGGER.warn("Issue publishing notification " + details, e);
		}
	}

Expected outcome:

PMD reports a violation at line ..., but that's wrong. That's a false positive.

Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Maven

Activity

  1. added
    a:false-positive
    on Feb 12, 2024
  2. changed the title [-][java] 7.0.0-rc4 ExceptionAsFlowControl false-positive on Lambda/asynchronous[/-] [+][java] ExceptionAsFlowControl false-positive on Lambda/asynchronous (7.0.0-rc4)[/+] on Feb 13, 2024
  3. added
    needs:pmd7-revalidation
    and removed
    needs:pmd7-revalidation
    on Mar 17, 2024
  4. added this to the 7.29.0 milestone on Sep 26, 2026
  5. added a commit that references this issue on Sep 26, 2026
    5ce9238
  6. changed the title [-][java] ExceptionAsFlowControl false-positive on Lambda/asynchronous (7.0.0-rc4)[/-] [+][java] ExceptionAsFlowControl: False positive on Lambda/asynchronous[/+] 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

    a:false-positive

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions