From 713dc2a9a58c73a297082b28565493073481b677 Mon Sep 17 00:00:00 2001 From: Xavier Le Vourch Date: Mon, 28 Apr 2008 18:34:24 +0000 Subject: [PATCH] Bug fix: NPE in MoreThanOneLogger git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/branches/pmd/4.2.x@6073 51baf565-9d33-0410-a72c-fc3788e3496d --- pmd/etc/changelog.txt | 1 + .../pmd/rules/loggingjava/xml/MoreThanOneLogger.xml | 11 +++++++++++ .../net/sourceforge/pmd/rules/MoreThanOneLogger.java | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index b2830a2420..0242b5a7ca 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -2,6 +2,7 @@ Fixed false positive in UnusedImports: javadoc comments are parsed to check @see and other tags Fixed parsing bug: constant fields in annotation classes +Bug fix: NPE in MoreThanOneLogger April 11, 2008 - 4.2.1: diff --git a/pmd/regress/test/net/sourceforge/pmd/rules/loggingjava/xml/MoreThanOneLogger.xml b/pmd/regress/test/net/sourceforge/pmd/rules/loggingjava/xml/MoreThanOneLogger.xml index c30252f1e8..5e50b87a11 100644 --- a/pmd/regress/test/net/sourceforge/pmd/rules/loggingjava/xml/MoreThanOneLogger.xml +++ b/pmd/regress/test/net/sourceforge/pmd/rules/loggingjava/xml/MoreThanOneLogger.xml @@ -37,6 +37,17 @@ public class Foo { class Bar { Logger log2; } +} + ]]> + + + + 0 + diff --git a/pmd/src/net/sourceforge/pmd/rules/MoreThanOneLogger.java b/pmd/src/net/sourceforge/pmd/rules/MoreThanOneLogger.java index 820e06fa21..019f98f259 100644 --- a/pmd/src/net/sourceforge/pmd/rules/MoreThanOneLogger.java +++ b/pmd/src/net/sourceforge/pmd/rules/MoreThanOneLogger.java @@ -3,6 +3,7 @@ package net.sourceforge.pmd.rules; import java.util.Stack; import net.sourceforge.pmd.AbstractRule; +import net.sourceforge.pmd.ast.ASTAnnotationTypeDeclaration; import net.sourceforge.pmd.ast.ASTClassOrInterfaceDeclaration; import net.sourceforge.pmd.ast.ASTClassOrInterfaceType; import net.sourceforge.pmd.ast.ASTEnumDeclaration; @@ -44,6 +45,10 @@ public class MoreThanOneLogger extends AbstractRule { return init (node, data); } + public Object visit(ASTAnnotationTypeDeclaration node, Object data) { + return init (node, data); + } + private Object init(SimpleJavaNode node, Object data) { stack.push(count); count = NumericConstants.ZERO;