diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symboltable/ClassScope.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symboltable/ClassScope.java index 38b5ff639a..e6770b9ecb 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symboltable/ClassScope.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symboltable/ClassScope.java @@ -324,12 +324,18 @@ public class ClassScope extends AbstractJavaScope { ASTClassOrInterfaceType classInterface = (ASTClassOrInterfaceType)child.jjtGetChild(0); type = convertToSimpleType(classInterface); } - if (type == null && parameterTypes.size() > i) { + if (type == null && !parameterTypes.isEmpty()) { // replace the unknown type with the correct parameter type of the method. // in case the argument is itself a method call, we can't determine the result type of the called // method. Therefore the parameter type is used. // This might cause confusion, if method overloading is used. - type = parameterTypes.get(i); + + // the method might be vararg, so, there might be more arguments than parameterTypes + if (parameterTypes.size() > i) { + type = parameterTypes.get(i); + } else { + type = parameterTypes.get(parameterTypes.size() - 1); // last parameter is the vararg type + } } if (type != null && type.getType() == null) { Class typeBound = resolveGenericType(argument, type.getTypeImage()); diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedPrivateMethod.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedPrivateMethod.xml index f4b5babd88..a487e6911a 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedPrivateMethod.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/unusedcode/xml/UnusedPrivateMethod.xml @@ -1324,6 +1324,33 @@ public class SuperClassFalsePositive { super(message); } } +} + ]]> + + + #1286 UnusedPrivateMethod returns false positives for varags + 0 + diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index c55b618bba..a899a2c828 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -16,3 +16,4 @@ * [#1281](https://sourceforge.net/p/pmd/bugs/1281/): UnusedPrivateMethod incorrectly flagged for methods nested private classes * [#1282](https://sourceforge.net/p/pmd/bugs/1282/): False Positive with implicit String.valuesOf() (Java) * [#1285](https://sourceforge.net/p/pmd/bugs/1285/): Prevent to modify the System environment +* [#1286](https://sourceforge.net/p/pmd/bugs/1286/): UnusedPrivateMethod returns false positives for varags and enums