Affects PMD Version: 3.26.0
Rule: NonExhaustiveSwitch
Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/pmd/pmd_rules_java_bestpractices.html#nonexhaustiveswitch
Description:
The switch is exhaustive but PMD Report an error.
Code Sample demonstrating the issue:
public class BugSealedClassTest { sealed interface SealedInterface permits SealedClass1, SealedClass2 { } static final class SealedClass1 implements SealedInterface { void method1() { } } static final class SealedClass2 implements SealedInterface { void method2() { } } void testSealedClass(SealedInterface sealedInterface) { switch (sealedInterface) { case SealedClass1 sealedClass1 -> sealedClass1.method1(); case SealedClass2 sealedClass2 -> sealedClass2.method2(); case null -> throw new IllegalStateException("Unexpected value: " + sealedInterface); } } }
Expected outcome:
[WARNING] PMD Failure: BugSealedClassTest:19 Rule:NonExhaustiveSwitch Priority:3 Switch statements or expressions should be exhaustive, add a default case (or missing enum branches).
PMD reports a violation at line 19, but that's wrong. That's a false positive.
Running PMD through: Maven*
This bug is very close to : #5514
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