#1275 False positive: UnusedModifier rule for static inner class in enum

This commit is contained in:
Andreas Dangel
2014-10-23 21:36:59 +02:00
parent 76af873708
commit 0e68c00f41
3 changed files with 11 additions and 14 deletions

View File

@ -15,10 +15,7 @@ public class UnusedModifierRule extends AbstractJavaRule {
public Object visit(ASTClassOrInterfaceDeclaration node, Object data) {
if (!node.isInterface() && node.isNested() && (node.isPublic() || node.isStatic())) {
ASTClassOrInterfaceDeclaration parentClassInterface = node.getFirstParentOfType(ASTClassOrInterfaceDeclaration.class);
ASTEnumDeclaration parentEnum = node.getFirstParentOfType(ASTEnumDeclaration.class);
if (parentClassInterface != null && parentClassInterface.isInterface()
||
parentEnum != null) {
if (parentClassInterface != null && parentClassInterface.isInterface()) {
addViolation(data, node, getMessage());
}
} else if (node.isInterface() && node.isNested() && (node.isPublic() || node.isStatic())) {

View File

@ -270,17 +270,16 @@ public enum Testing {
]]></code>
</test-code>
<test-code>
<description>False negative: static class nested in enum</description>
<expected-problems>1</expected-problems>
<description>#1275 False positive: UnusedModifier rule for static inner class in enum</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public enum Testing {
Test;
public enum MyEnum
{
VALUE_1,
VALUE_2;
public void test(ITesting tester) {
tester.test();
}
public static class ITesting {
public void test() {};
private static class MyInnerClass // violation detected by PMD
{
}
}
]]></code>

View File

@ -18,3 +18,4 @@
* [#1272](https://sourceforge.net/p/pmd/bugs/1272/): varargs in methods are causing IndexOutOfBoundException when trying to process files
* [#1273](https://sourceforge.net/p/pmd/bugs/1273/): CheckResultSet false positive in try-with-resources nested in if
* [#1274](https://sourceforge.net/p/pmd/bugs/1274/): ant integration broken with pmd-5.2.0
* [#1275](https://sourceforge.net/p/pmd/bugs/1275/): False positive: UnusedModifier rule for static inner class in enum