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] [7.0-rc1] ExceptionAsFlowControl when simply propagating #4434

Closed
ben-manes opened this issue Mar 26, 2023 · 0 comments · Fixed by #4543
Closed

[java] [7.0-rc1] ExceptionAsFlowControl when simply propagating #4434

ben-manes opened this issue Mar 26, 2023 · 0 comments · Fixed by #4543
Assignees
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@ben-manes
Copy link

Affects PMD Version:
7.0-rc1 when upgrading from 6.55

Rule:
ExceptionAsFlowControl

Description:
A multi-catch block that rethrows the exception prior to other catches which would wrap it.

Code Sample demonstrating the issue:

public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) throws ExecutionException {
  try {
    // ...
  } catch (NullPointerException | InvalidCacheLoadException e) {
    throw e; // <-- Violation
  } catch (CacheLoaderException e) {
    throw new ExecutionException(e.getCause());
  } catch (Exception e) {
    throw new UncheckedExecutionException(e);
  } catch (Error e) {
    throw new ExecutionError(e);
  }
}

Expected outcome:

PMD reports a violation when the alternative is worse (instanceof checks within a catch clause).

# File Line Problem
1 /guava/CaffeinatedGuavaLoadingCache.java 108 Avoid using exceptions as flow control.

Running PMD through: Gradle
This requires workaround in gradle/gradle#24502

@ben-manes ben-manes added the a:false-positive PMD flags a piece of code that is not problematic label Mar 26, 2023
@jsotuyod jsotuyod added this to the 7.0.0 milestone Mar 31, 2023
@oowekyala oowekyala self-assigned this May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
3 participants