From 8dc25abcfeec17b9ec845bcb76e5b46e02baae93 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sun, 28 Jun 2015 21:51:04 +0200 Subject: [PATCH] #1376 CompareObjectsWithEquals fails for type annotated method parameter --- .../rule/design/CompareObjectsWithEqualsRule.java | 7 ++----- .../rule/design/xml/CompareObjectsWithEquals.xml | 12 ++++++++++++ src/site/markdown/overview/changelog.md | 1 + 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CompareObjectsWithEqualsRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CompareObjectsWithEqualsRule.java index ffd02f9737..8b0130d547 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CompareObjectsWithEqualsRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/CompareObjectsWithEqualsRule.java @@ -78,11 +78,8 @@ public class CompareObjectsWithEqualsRule extends AbstractJavaRule { } if (nd0.isReferenceType() && nd1.isReferenceType()) { - - ASTReferenceType type0 = (ASTReferenceType) ((Node) nd0.getAccessNodeParent()).jjtGetChild(0) - .jjtGetChild(0); - ASTReferenceType type1 = (ASTReferenceType) ((Node) nd1.getAccessNodeParent()).jjtGetChild(0) - .jjtGetChild(0); + ASTReferenceType type0 = ((Node) nd0.getAccessNodeParent()).getFirstDescendantOfType(ASTReferenceType.class); + ASTReferenceType type1 = ((Node) nd1.getAccessNodeParent()).getFirstDescendantOfType(ASTReferenceType.class); // skip, if it is an enum if (type0.getType() != null && type0.getType().equals(type1.getType()) && type0.getType().isEnum()) { return data; diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/CompareObjectsWithEquals.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/CompareObjectsWithEquals.xml index 1f666c22fb..f07bf55aec 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/CompareObjectsWithEquals.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/CompareObjectsWithEquals.xml @@ -189,4 +189,16 @@ class SomeObject { */ ]]> + + #1376 CompareObjectsWithEquals fails for type annotated method parameter + 1 + + diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index f61c9a7366..a318814534 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -19,5 +19,6 @@ * [#1366](https://sourceforge.net/p/pmd/bugs/1366/): UselessParentheses false positive on multiple equality operators * [#1372](https://sourceforge.net/p/pmd/bugs/1372/): False Negative for CloseResource rule. * [#1375](https://sourceforge.net/p/pmd/bugs/1375/): CloseResource not detected properly +* [#1376}(https://sourceforge.net/p/pmd/bugs/1376/): CompareObjectsWithEquals fails for type annotated method parameter **API Changes:**