From d9517956343b9a2786be2b0cecaa2e8ff1aa07c3 Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Sat, 14 Jun 2008 00:37:10 +0000 Subject: [PATCH] Fixed bug 1977230 - false positive: UselessOverridingMethod git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6205 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + .../basic/xml/UselessOverridingMethod.xml | 22 +++++++++++++++++++ .../pmd/rules/UselessOverridingMethod.java | 7 +++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 941428e1ff..89b06825bc 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -5,6 +5,7 @@ Updates to RuleChain to honor RuleSet exclude-pattern Upgrading UselessOperationOnImmutable to detect more use cases, especially on String Fixed bug 1988829 - Violation reported without source file name (actually a fix to ConsecutiveLiteralAppends) Fixed bug 1989814 - false +: ConsecutiveLiteralAppends +Fixed bug 1977230 - false positive: UselessOverridingMethod New rule: Basic ruleset: EmptyInitializer diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/UselessOverridingMethod.xml b/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/UselessOverridingMethod.xml index 263afd3a6c..31fec5b345 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/UselessOverridingMethod.xml +++ b/pmd/regress/test/net/sourceforge/pmd/rules/basic/xml/UselessOverridingMethod.xml @@ -263,6 +263,28 @@ private static class ExposingSerializer extends Serializer { public void exposedWriteAttributeValue(String text) throws IOException { writeAttributeValue(text); } +} + ]]> + + + + + + 0 + + diff --git a/pmd/src/net/sourceforge/pmd/rules/UselessOverridingMethod.java b/pmd/src/net/sourceforge/pmd/rules/UselessOverridingMethod.java index dd0231fec4..f8371c6ed0 100644 --- a/pmd/src/net/sourceforge/pmd/rules/UselessOverridingMethod.java +++ b/pmd/src/net/sourceforge/pmd/rules/UselessOverridingMethod.java @@ -156,8 +156,13 @@ public class UselessOverridingMethod extends AbstractRule { if (!primaryPrefix.hasImageEqualTo(methodDeclarator.getImage())) return super.visit(node, data); + List primarySuffixList = findFirstDegreeChildrenOfType(primaryExpression, ASTPrimarySuffix.class); + if (primarySuffixList.size() != 1) { + // extra method call on result of super method + return super.visit(node, data); + } //Process arguments - ASTPrimarySuffix primarySuffix = findFirstDegreeChildrenOfType(primaryExpression, ASTPrimarySuffix.class).get(0); + ASTPrimarySuffix primarySuffix = primarySuffixList.get(0); ASTArguments arguments = (ASTArguments) primarySuffix.jjtGetChild(0); ASTFormalParameters formalParameters = (ASTFormalParameters) methodDeclarator.jjtGetChild(0); if (formalParameters.jjtGetNumChildren() != arguments.jjtGetNumChildren())