Please, prefix the report title with the language it applies to within brackets, such as [java] or [apex]. If not specific to a language, you can use [core]
Rule Set:
rulesets/java/unusedcode.xml/UnusedPrivateMethod
Description:
(PMD 5.6.1) If the invoked private method contains a "weaker" formal parameter type than actual invocation then PMD does not detect its invocation
Code Sample demonstrating the issue:
@Test
public void testFlipCaseDigit() {
testNoChangeOnFlip("0123456789");
}
@Test
public void testFlipCaseWhitespace() {
testNoChangeOnFlip(" \r\t\n");
}
@Test
public void testFlipCaseOtherChars() {
testNoChangeOnFlip("!@#$%^");
}
private static void testNoChangeOnFlip(CharSequence chars) {
for (int index = 0; index < chars.length(); index++) {
char expected = chars.charAt(index);
char actual = CharacterUtils.flipCase(expected);
assertEquals("Unexpected flipped value", expected, actual);
}
}
yields CharacterUtilsTest:44 Rule:UnusedPrivateMethod Priority:3 Avoid unused private methods such as 'testNoChangeOnFlip(CharSequence)'..
A similar problem occurs with this (more complex) code:
public class ExceptionUtils {
private static final class ExceptionThrower {
private static synchronized void spit(Throwable t) {
...
}
}
@SuppressWarnings("synthetic-access")
public static void rethrowException(Throwable t) {
ExceptionThrower.spit(t);
}
}
which yields ExceptionThrower:405 Rule:UnusedPrivateMethod Priority:3 Avoid unused private methods such as 'spit(Throwable)'.. - although in this case, the types are the same
Running PMD through: Maven
Please, prefix the report title with the language it applies to within brackets, such as [java] or [apex]. If not specific to a language, you can use [core]
Rule Set:
rulesets/java/unusedcode.xml/UnusedPrivateMethodDescription:
(PMD 5.6.1) If the invoked private method contains a "weaker" formal parameter type than actual invocation then PMD does not detect its invocation
Code Sample demonstrating the issue:
yields
CharacterUtilsTest:44 Rule:UnusedPrivateMethod Priority:3 Avoid unused private methods such as 'testNoChangeOnFlip(CharSequence)'..A similar problem occurs with this (more complex) code:
which yields
ExceptionThrower:405 Rule:UnusedPrivateMethod Priority:3 Avoid unused private methods such as 'spit(Throwable)'..- although in this case, the types are the sameRunning PMD through: Maven