#1403 False positive UnusedPrivateMethod with JAVA8

This commit is contained in:
Andreas Dangel
2015-09-14 22:36:05 +02:00
parent 9f6190f3b6
commit 2500412b14
3 changed files with 28 additions and 4 deletions

View File

@ -533,11 +533,14 @@ public class ClassScope extends AbstractJavaScope {
for (ASTTypeParameter type : types) {
if (typeImage.equals(type.getImage())) {
ASTClassOrInterfaceType bound = type.getFirstDescendantOfType(ASTClassOrInterfaceType.class);
if (bound != null && bound.getType() != null) {
return bound.getType();
}
if (bound != null) {
return this.getEnclosingScope(SourceFileScope.class).resolveType(bound.getImage());
if (bound.getType() != null) {
return bound.getType();
} else {
return this.getEnclosingScope(SourceFileScope.class).resolveType(bound.getImage());
}
} else {
return Object.class; // type parameter found, but no binding.
}
}
}

View File

@ -1464,6 +1464,26 @@ public class UnusedPrivateMethod {
int index = fileName.lastIndexOf('.');
return fileName.substring(0, index);
}
}
]]></code>
</test-code>
<test-code>
<description>#1403 False positive UnusedPrivateMethod with JAVA8</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Something {
@Test public void mapMergeShouldReturnTheUnionWhenGivenDifferentSetsWithSomeCommonValues() {
final Map<String, Purse> actual
= Combiners.mapMerge(mapOf(annPurse5, bobPurse7), mapOf(bobPurse9, calPurse10), ADDITION);
assertEquals(mapOf(annPurse5, bobPurse16, calPurse10), actual);
}
private static Map<String, Purse> mapOf(final Purse... values) {
return mapOf2(Purse::getOwner, values);
}
private static <K, V> Map<K, V> mapOf2(final Function<V, K> keyMapper, final V... values) {
return Stream.of(values).collect(Collectors.toMap(keyMapper, Function.identity()));
}
}
]]></code>
</test-code>

View File

@ -27,5 +27,6 @@
* [#1400](https://sourceforge.net/p/pmd/bugs/1400/): False positive with JUnit4TestShouldUseBeforeAnnotation
* [#1401](https://sourceforge.net/p/pmd/bugs/1401/): False positive for StringBuilder.append called with constructor
* [#1402](https://sourceforge.net/p/pmd/bugs/1402/): Windows-Only: File exclusions are not case insensitive
* [#1403](https://sourceforge.net/p/pmd/bugs/1403/): False positive UnusedPrivateMethod with JAVA8
**API Changes:**