-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
a:false-negativePMD doesn't flag a problematic piece of codePMD doesn't flag a problematic piece of code
Milestone
Description
Affects PMD Version:
7.17.0
Rule:
Description:
Two exception handling blocks are not considered equivalent if both contain e.getMessage() and one of the exception types overrides getMessage().
Code Sample demonstrating the issue:
public class Foo {
public void bar() {
try {
// nothing
} catch (NullPointerException ex) {
System.out.println(ex.getMessage());
} catch (CustomException ex) {
System.out.println(ex.getMessage());
} catch (RuntimeException ex) {
System.out.println(ex.getMessage());
}
}
public static class CustomException extends RuntimeException {
@Override public String getMessage() {
return "";
}
}
}Expected outcome:
PMD should report a violation at lines 7 and 9, but doesn't. This is a false-negative.
In Java < 17 only the second violation is missing because NPE does not override getMessage.
Running PMD through: IntelliJ
Metadata
Metadata
Assignees
Labels
a:false-negativePMD doesn't flag a problematic piece of codePMD doesn't flag a problematic piece of code