A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pmd/pmd/issues/4434 below:

[java] [7.0-rc1] ExceptionAsFlowControl when simply propagating · Issue #4434 · pmd/pmd · GitHub

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4