diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTType.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTType.java index b398ca9a73..bdd26c4f59 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTType.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTType.java @@ -23,11 +23,11 @@ public class ASTType extends AbstractJavaTypeNode { } public String getTypeImage() { - ASTPrimitiveType prim = getFirstDescendantOfType(ASTPrimitiveType.class); - if (prim != null) { - return prim.getImage(); + ASTClassOrInterfaceType refType = getFirstDescendantOfType(ASTClassOrInterfaceType.class); + if (refType != null) { + return refType.getImage(); } - return getFirstDescendantOfType(ASTClassOrInterfaceType.class).getImage(); + return getFirstDescendantOfType(ASTPrimitiveType.class).getImage(); } public int getArrayDepth() { 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 1b66422495..b5d810c04b 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 @@ -1531,4 +1531,22 @@ public class Something { } ]]> + + + #521 UnusedPrivateMethod returns false positives with primitive data type in map argument + 0 + map = new LinkedHashMap<>(); + addToMap(map); + } + + private void addToMap(Map map) { + map.put("foo", new double[]{0., 1.}); + } + } + ]]> + + diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 26d98f53d7..3b8c976417 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -13,6 +13,7 @@ This is a major release. * [Java Type Resolution](#Java_Type_Resolution) * [Metrics Framework](#Metrics_Framework) * [Configuration Error Reporting](#Configuration_Error_Reporting) + * [Java Symbol Table](#Java_Symbol_Table) * [Modified Rules](#Modified_Rules) * [Removed Rules](#Removed_Rules) * [Fixed Issues](#Fixed_Issues) @@ -79,6 +80,13 @@ and include them to such reports. * The deprecated rule `UseSingleton` has been removed from the ruleset `java-design`. The rule has been renamed long time ago to `UseUtilityClass`. + +#### Java Symbol Table + +* A [bug in symbol table](https://github.com/pmd/pmd/pull/549/commits/0958621ca884a8002012fc7738308c8dfc24b97c) prevented + the symbol table analysis to properly match primitive arrays types. The issue [affected the `java-unsedcode/UnusedPrivateMethod`](https://github.com/pmd/pmd/issues/521) + rule, but other rules may now produce improved results as consequence of this fix. + ### Fixed Issues * apex @@ -95,6 +103,8 @@ and include them to such reports. * [#408](https://github.com/pmd/pmd/issues/408): \[java] DFA not analyzing asserts * java-sunsecure * [#468](https://github.com/pmd/pmd/issues/468): \[java] ArrayIsStoredDirectly false positive +* java-unusedcode + * [#521](https://github.com/pmd/pmd/issues/521): \[java] UnusedPrivateMethod returns false positives with primitive data type in map argument * java-unnecessarycode * [#412](https://github.com/pmd/pmd/issues/412): \[java] java-unnecessarycode/UnnecessaryFinalModifier missing cases