Affects PMD Version:
7.12.0
(also tested with other 7.x versions and 6.55.0 which have the same problem)
Description:
Having a switch statement with a negated yield gives a parse exception.
case ONE: {
yield !true;
}
Code Sample demonstrating the issue:
src_pmd/com/example/PMDYield.java' at line 15, column 11: Encountered "!".
Was expecting one of:
";" ...
"=" ...
"++" ...
"--" ...
"+=" ...
"-=" ...
"*=" ...
"/=" ...
"&=" ...
"|=" ...
"^=" ...
"%=" ...
"<<=" ...
">>=" ...
">>>=" ...
public class PMDYield {
private boolean testPMDYield(TestEnum myEnum) {
return switch (myEnum) {
case ONE -> {
yield true;
}
case TWO -> {
yield false;
}
case THREE -> {
yield !Collections.emptyList().isEmpty();
}
};
}
private enum TestEnum {
ONE(1),
TWO(2),
THREE(3);
private final int value;
TestEnum(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
}
Running PMD through:
Running this through Gradle 8.6 on Linux with Java 21
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