Affects PMD Version:
7.18.0
Rule:
UnusedLocalVariable
Description:
When using an instanceof guard with pattern matching in a switch expression, then the local variable matched by that pattern will be marked as unused by PMD.
Code Sample demonstrating the issue:
public class Reproducer {
public static boolean customEquals(Object foo, Object bar) {
return switch (foo) {
case String fooString when bar instanceof String barString -> fooString.equals(barString);
default -> false;
};
}
}
Expected outcome:
PMD reports a violation at line 4, but that's wrong. That's a false positive.
Running PMD through: Gradle 9.2.1 and Java 21
Affects PMD Version:
7.18.0
Rule:
UnusedLocalVariable
Description:
When using an instanceof guard with pattern matching in a switch expression, then the local variable matched by that pattern will be marked as unused by PMD.
Code Sample demonstrating the issue:
Expected outcome:
PMD reports a violation at line 4, but that's wrong. That's a false positive.
Running PMD through: Gradle 9.2.1 and Java 21