Affects PMD Version:
6.20.0.
Rule:
DoNotCallSystemExit
Description:
This rule must make an exception if the exit methods are called from main(). This rule could add a property to dissuade System.exit() being called from any method other than main().
package pmdtests; import java.util.concurrent.ThreadLocalRandom; public final class ThrowSwitch { private ThrowSwitch() { throw new IllegalStateException("Private constructor"); } @SuppressWarnings({"fallthrough", "PMD.MissingBreakInSwitch"}) public static void main(String... args) { int errCode = getSimulatedErrorCode(); switch (errCode) { case 1: case 2: case 3: case 4: case 5: throw new AssertionError("Error code: " + errCode); default: System.exit(1); } } public static int getSimulatedErrorCode() { return ThreadLocalRandom.current().nextInt(0, 6); } private static void anotherExit() { System.exit(1); } }
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
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