From 7cd887ba8cfc11d986b16bfa3e0a7bd2796e5ecd Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Wed, 10 Sep 2008 19:54:21 +0000 Subject: [PATCH] merge from trunk: Fixed ClassCastException in symbol table code git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6468 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + .../sourceforge/pmd/symboltable/MethodScopeTest.java | 11 +++++++++++ .../pmd/symboltable/MethodNameDeclaration.java | 4 ++++ .../pmd/symboltable/VariableNameDeclaration.java | 3 +++ 4 files changed, 19 insertions(+) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index df52ffdbb7..2e0e2e7c6f 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -3,6 +3,7 @@ Fixed bug 1481051 - false + UnusedNullCheckInEquals (and other false positives too) Fixed bug 1943204 - Ant task: path should be relative to Ant basedir Fixed ClassCastException on generic method in BeanMembersShouldSerialize +Fixed ClassCastException in symbol table code August 31, 2008 - 4.2.3: diff --git a/pmd/regress/test/net/sourceforge/pmd/symboltable/MethodScopeTest.java b/pmd/regress/test/net/sourceforge/pmd/symboltable/MethodScopeTest.java index 2162b9fed6..446943d569 100644 --- a/pmd/regress/test/net/sourceforge/pmd/symboltable/MethodScopeTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/symboltable/MethodScopeTest.java @@ -32,6 +32,10 @@ public class MethodScopeTest extends STBBaseTst { MethodScope ms = (MethodScope) meth.getScope(); assertEquals(ms.getName(), "foo"); } + @Test + public void testGenerics() { + parseCode15(TEST_GENERICS); + } public static final String TEST1 = "public class Foo {" + PMD.EOL + @@ -40,6 +44,13 @@ public class MethodScopeTest extends STBBaseTst { " }" + PMD.EOL + "}"; + private static final String TEST_GENERICS = + "public class Tree {" + PMD.EOL + + " private List subForest;" + PMD.EOL + + " public Tree fmap(final F f) { return Tree.foo(); }" + PMD.EOL + + " public List subForest() { return null; }" + PMD.EOL + + "}" + PMD.EOL; + public static junit.framework.Test suite() { return new junit.framework.JUnit4TestAdapter(MethodScopeTest.class); } diff --git a/pmd/src/net/sourceforge/pmd/symboltable/MethodNameDeclaration.java b/pmd/src/net/sourceforge/pmd/symboltable/MethodNameDeclaration.java index 3a807825ac..706bffce58 100644 --- a/pmd/src/net/sourceforge/pmd/symboltable/MethodNameDeclaration.java +++ b/pmd/src/net/sourceforge/pmd/symboltable/MethodNameDeclaration.java @@ -55,6 +55,10 @@ public class MethodNameDeclaration extends AbstractNameDeclaration { } public boolean equals(Object o) { + if (!(o instanceof MethodNameDeclaration)) { + return false; + } + MethodNameDeclaration other = (MethodNameDeclaration) o; // compare name diff --git a/pmd/src/net/sourceforge/pmd/symboltable/VariableNameDeclaration.java b/pmd/src/net/sourceforge/pmd/symboltable/VariableNameDeclaration.java index 7a2d910cac..bfeaaedbc7 100644 --- a/pmd/src/net/sourceforge/pmd/symboltable/VariableNameDeclaration.java +++ b/pmd/src/net/sourceforge/pmd/symboltable/VariableNameDeclaration.java @@ -67,6 +67,9 @@ public class VariableNameDeclaration extends AbstractNameDeclaration { } public boolean equals(Object o) { + if (!(o instanceof VariableNameDeclaration)) { + return false; + } VariableNameDeclaration n = (VariableNameDeclaration) o; return n.node.getImage().equals(node.getImage()); }