From df66f04d8426d1367ba891b2d6e731ac94e35a98 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Mon, 27 Jan 2003 19:42:24 +0000 Subject: [PATCH] Fixed bug, thx to Don for the good catch git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@1380 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + .../pmd/rules/OverrideBothEqualsAndHashcodeRuleTest.java | 3 +++ .../pmd/rules/OverrideBothEqualsAndHashcodeRule.java | 5 +++++ pmd/test-data/OverrideBothEqualsAndHashcode6.java | 3 +++ 4 files changed, 12 insertions(+) create mode 100644 pmd/test-data/OverrideBothEqualsAndHashcode6.java diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 183f02820b..4b23964f66 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -3,6 +3,7 @@ Added numbering to the HTMLRenderer; thx to Luke Francl for the code. Fixed bug 672742 - grammar typo was hosing up ASTConstructorDeclaration which was hosing up UseSingletonRule Fixed bug 674393 - OnlyOneReturn rule no longer counts returns that are inside anonymous inner classes as being inside the containing method. Thx to C. Lamont Gilbert for the bug report. Fixed bug 674420 - AvoidReassigningParametersRule no longer counts parameter field reassignment as a violation. Thx to C. Lamont Gilbert for the bug report. +Fixed bug in OverrideBothEqualsAndHashcodeRule - it no longer bails out with a NullPtrException on interfaces that declare a method signature "equals(Object)". Thx to Don Leckie for catching that. January 22, 2003 - 1.02: Added new rules: ImportFromSamePackageRule, SwitchDensityRule, NullAssignmentRule, UnusedModifierRule, ForLoopShouldBeWhileLoopRule diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/OverrideBothEqualsAndHashcodeRuleTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/OverrideBothEqualsAndHashcodeRuleTest.java index 236d901045..74eb6d1d3f 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/OverrideBothEqualsAndHashcodeRuleTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/OverrideBothEqualsAndHashcodeRuleTest.java @@ -23,4 +23,7 @@ public class OverrideBothEqualsAndHashcodeRuleTest extends RuleTst { public void testEqualsSignatureUsesStringNotObject() throws Throwable{ runTest("OverrideBothEqualsAndHashcode5.java", 1, new OverrideBothEqualsAndHashcodeRule()); } + public void testInterface() throws Throwable{ + runTest("OverrideBothEqualsAndHashcode6.java", 0, new OverrideBothEqualsAndHashcodeRule()); + } } diff --git a/pmd/src/net/sourceforge/pmd/rules/OverrideBothEqualsAndHashcodeRule.java b/pmd/src/net/sourceforge/pmd/rules/OverrideBothEqualsAndHashcodeRule.java index 47ed8b24aa..5efc0ef7ed 100644 --- a/pmd/src/net/sourceforge/pmd/rules/OverrideBothEqualsAndHashcodeRule.java +++ b/pmd/src/net/sourceforge/pmd/rules/OverrideBothEqualsAndHashcodeRule.java @@ -12,6 +12,7 @@ import net.sourceforge.pmd.ast.ASTClassBody; import net.sourceforge.pmd.ast.ASTMethodDeclarator; import net.sourceforge.pmd.ast.AccessNode; import net.sourceforge.pmd.ast.SimpleNode; +import net.sourceforge.pmd.ast.ASTInterfaceDeclaration; public class OverrideBothEqualsAndHashcodeRule extends AbstractRule implements Rule { @@ -48,6 +49,10 @@ public class OverrideBothEqualsAndHashcodeRule extends AbstractRule implements R return data; } + public Object visit(ASTInterfaceDeclaration node, Object data) { + return data; + } + public Object visit(ASTMethodDeclarator node, Object data) { AccessNode parent = (AccessNode)node.jjtGetParent(); // hashcode has no params & (TODO) returns an int diff --git a/pmd/test-data/OverrideBothEqualsAndHashcode6.java b/pmd/test-data/OverrideBothEqualsAndHashcode6.java new file mode 100644 index 0000000000..114d5e46bb --- /dev/null +++ b/pmd/test-data/OverrideBothEqualsAndHashcode6.java @@ -0,0 +1,3 @@ +public interface OverrideBothEqualsAndHashcode6 { + public boolean equals(Object o); +}