From 2500412b147a31cef5940aba9ca0b504dd39003f Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 14 Sep 2015 22:36:05 +0200 Subject: [PATCH] #1403 False positive UnusedPrivateMethod with JAVA8 --- .../pmd/lang/java/symboltable/ClassScope.java | 11 ++++++---- .../unusedcode/xml/UnusedPrivateMethod.xml | 20 +++++++++++++++++++ src/site/markdown/overview/changelog.md | 1 + 3 files changed, 28 insertions(+), 4 deletions(-) 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 d1c24b63fa..33cba6f06c 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 @@ -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. } } } 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 625901e76d..83c72e23d9 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 @@ -1464,6 +1464,26 @@ public class UnusedPrivateMethod { int index = fileName.lastIndexOf('.'); return fileName.substring(0, index); } +} + ]]> + + + + #1403 False positive UnusedPrivateMethod with JAVA8 + 0 + actual + = Combiners.mapMerge(mapOf(annPurse5, bobPurse7), mapOf(bobPurse9, calPurse10), ADDITION); + assertEquals(mapOf(annPurse5, bobPurse16, calPurse10), actual); + } + private static Map mapOf(final Purse... values) { + return mapOf2(Purse::getOwner, values); + } + private static Map mapOf2(final Function keyMapper, final V... values) { + return Stream.of(values).collect(Collectors.toMap(keyMapper, Function.identity())); + } } ]]> diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index f8625f07df..2d089767b8 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -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:**