#1286 UnusedPrivateMethod returns false positives for varags and enums
This commit is contained in:
@ -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());
|
||||
|
@ -1324,6 +1324,33 @@ public class SuperClassFalsePositive {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>#1286 UnusedPrivateMethod returns false positives for varags</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class VaragsFalsePositive {
|
||||
|
||||
enum Sizes
|
||||
{
|
||||
TINY,
|
||||
MEDIUM
|
||||
}
|
||||
|
||||
public boolean containsTiny(){
|
||||
return hasTiny(Sizes.MEDIUM, Sizes.TINY);
|
||||
}
|
||||
|
||||
private boolean hasTiny(Sizes... sizes) {
|
||||
for (Sizes size : sizes) {
|
||||
if (size==Sizes.TINY) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user