From 5fb6daea58aa5428b7cc56fb2f7fe650e183b9ed Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 25 Apr 2013 19:11:01 +0200 Subject: [PATCH] pmd: fix #1085 NullPointerException by at net.sourceforge.pmd.lang.java.rule.design.GodClassRule.visit(GodClassRule.java:313) --- pmd/etc/changelog.txt | 1 + .../pmd/lang/java/rule/design/GodClassRule.java | 6 +++--- .../pmd/lang/java/rule/design/xml/GodClass.xml | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 06af43d31e..93ed23a0f6 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -4,6 +4,7 @@ Fixed bug 254: False+ : UnusedImport with Javadoc @throws Fixed bug 1080: net.sourceforge.pmd.cpd.CPDTest test failing Fixed bug 1081: Regression: CPD skipping all files when using relative paths Fixed bug 1082: CPD performance issue on larger projects +Fixed bug 1085: NullPointerException by at net.sourceforge.pmd.lang.java.rule.design.GodClassRule.visit(GodClassRule.java:313) Fixed bug 1086: Unsupported Element and Attribute in Ant Task Example Fixed bug 1087: PreserveStackTrace (still) ignores initCause() diff --git a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GodClassRule.java b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GodClassRule.java index 74e7560f75..33122a7a56 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GodClassRule.java +++ b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/design/GodClassRule.java @@ -13,7 +13,7 @@ import java.util.Set; import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.lang.java.ast.ASTAllocationExpression; import net.sourceforge.pmd.lang.java.ast.ASTCatchStatement; -import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration; +import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit; import net.sourceforge.pmd.lang.java.ast.ASTConditionalAndExpression; import net.sourceforge.pmd.lang.java.ast.ASTConditionalExpression; import net.sourceforge.pmd.lang.java.ast.ASTConditionalOrExpression; @@ -77,12 +77,12 @@ public class GodClassRule extends AbstractJavaRule { /** - * Base entry point for the visitor - the class declaration. + * Base entry point for the visitor - the compilation unit (everything within one file). * The metrics are initialized. Then the other nodes are visited. Afterwards * the metrics are evaluated against fixed thresholds. */ @Override - public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { + public Object visit(ASTCompilationUnit node, Object data) { wmcCounter = 0; atfdCounter = 0; methodAttributeAccess = new HashMap>(); diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/GodClass.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/GodClass.xml index 50709138cb..a0d6aa48b2 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/GodClass.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/GodClass.xml @@ -125,4 +125,20 @@ public class Foo { } ]]> + + + #1085 NullPointerException by at net.sourceforge.pmd.lang.java.rule.design.GodClassRule.visit(GodClassRule.java:313) + 0 + + +