From b64dc670ae9aca71a8cccafcfd3865ade6c67547 Mon Sep 17 00:00:00 2001 From: Tom Copeland Date: Tue, 1 Jul 2003 13:53:43 +0000 Subject: [PATCH] Added workaround to prevent AccessorClassGenerationRule from crashing git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@2059 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + .../AccessorClassGenerationRuleTest.java | 34 +++++++++++++------ .../rules/AccessorClassGenerationRule.java | 12 ++++--- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 8f882f40da..453cd552de 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -2,6 +2,7 @@ Added new rules: VariableNamingConventionsRule, MethodNamingConventionsRule, ClassNamingConventionsRule Fixed bug 583047 - ASTName column numbers are now correct Fixed bug 761048 - Symbol table now creates a scope level for anonymous inner classes +Fixed bug 763529 - AccessorClassGenerationRule no longer crashes when given a final inner class ASTViewer now shows node images and modifiers ASTViewer now saves last edited text to ~/.pmd_astviewer Moved the PMD Swing UI into a separate module - pmd-swingui. diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/AccessorClassGenerationRuleTest.java b/pmd/regress/test/net/sourceforge/pmd/rules/AccessorClassGenerationRuleTest.java index 6c2238b043..4cb2eee4ad 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/AccessorClassGenerationRuleTest.java +++ b/pmd/regress/test/net/sourceforge/pmd/rules/AccessorClassGenerationRuleTest.java @@ -5,6 +5,22 @@ import net.sourceforge.pmd.rules.AccessorClassGenerationRule; public class AccessorClassGenerationRuleTest extends RuleTst { + public void testInnerClassHasPrivateConstructor() throws Throwable { + runTestFromString(TEST1, 1, new AccessorClassGenerationRule()); + } + + public void testInnerClassHasPublicConstructor() throws Throwable { + runTestFromString(TEST2, 0, new AccessorClassGenerationRule()); + } + + public void testOuterClassHasPrivateConstructor() throws Throwable { + runTestFromString(TEST3, 1, new AccessorClassGenerationRule()); + } + + public void testFinalInnerClass() throws Throwable { + runTestFromString(TEST4, 0, new AccessorClassGenerationRule()); + } + private static final String TEST1 = "public class Foo1 {" + PMD.EOL + " public class InnerClass {" + PMD.EOL + @@ -38,15 +54,11 @@ public class AccessorClassGenerationRuleTest extends RuleTst { " }" + PMD.EOL + "}"; - public void testInnerClassHasPrivateConstructor() throws Throwable { - runTestFromString(TEST1, 1, new AccessorClassGenerationRule()); - } - - public void testInnerClassHasPublicConstructor() throws Throwable { - runTestFromString(TEST2, 0, new AccessorClassGenerationRule()); - } - - public void testOuterClassHasPrivateConstructor() throws Throwable { - runTestFromString(TEST3, 1, new AccessorClassGenerationRule()); - } + private static final String TEST4 = + "public class Foo {" + PMD.EOL + + " void method() {" + PMD.EOL + + " final class Inner {}; " + PMD.EOL + + " Inner i = new Inner();" + PMD.EOL + + " }" + PMD.EOL + + "}"; } diff --git a/pmd/src/net/sourceforge/pmd/rules/AccessorClassGenerationRule.java b/pmd/src/net/sourceforge/pmd/rules/AccessorClassGenerationRule.java index 33b916738f..09f0a75330 100644 --- a/pmd/src/net/sourceforge/pmd/rules/AccessorClassGenerationRule.java +++ b/pmd/src/net/sourceforge/pmd/rules/AccessorClassGenerationRule.java @@ -201,7 +201,6 @@ public class AccessorClassGenerationRule extends AbstractRule { } private void processRule(RuleContext ctx) { - // try { //check constructors of outerIterator //against allocations of innerIterator for (Iterator outerIterator = classDataList.iterator(); outerIterator.hasNext();) { @@ -227,10 +226,6 @@ public class AccessorClassGenerationRule extends AbstractRule { } } } - // } - // catch(Exception e){ - // e.printStackTrace(); - // } } /** @@ -324,6 +319,13 @@ public class AccessorClassGenerationRule extends AbstractRule { } public Object visit(ASTAllocationExpression node, Object data) { + // TODO + // this is a hack to bail out here + // but I'm not sure why this is happening + // TODO + if (classID == -1) { + return data; + } AllocData ad = new AllocData(node, getPackageName(), getCurrentClassData().getClassQualifyingNamesList()); if (ad.isArray() == false) { getCurrentClassData().addInstantiation(ad);