diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt index 87f0b2f6f6..e4c4a051ce 100644 --- a/pmd/etc/changelog.txt +++ b/pmd/etc/changelog.txt @@ -1,6 +1,7 @@ ???? ??, 2012 - 5.0.2: Fixed bug 878: False positive: UnusedFormalParameter for abstract methods +Fixed bug 913: SignatureDeclareThrowsException is raised twice Fixed bug 1012: False positive: Useless parentheses. Fixed bug 1026: PMD doesn't handle 'value =' in SuppressWarnings annotation Fixed bug 1037: Facing a showstopper issue in PMD Report Class (report listeners) diff --git a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/strictexception/SignatureDeclareThrowsExceptionRule.java b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/strictexception/SignatureDeclareThrowsExceptionRule.java index e08cfa1dba..82f34ddd9c 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/strictexception/SignatureDeclareThrowsExceptionRule.java +++ b/pmd/src/main/java/net/sourceforge/pmd/lang/java/rule/strictexception/SignatureDeclareThrowsExceptionRule.java @@ -1,5 +1,6 @@ package net.sourceforge.pmd.lang.java.rule.strictexception; +import java.util.Collections; import java.util.List; import net.sourceforge.pmd.lang.ast.Node; @@ -8,6 +9,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTName; +import net.sourceforge.pmd.lang.java.ast.ASTNameList; import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; /** @@ -46,7 +48,11 @@ public class SignatureDeclareThrowsExceptionRule extends AbstractJavaRule { return super.visit(methodDeclaration, o); } - List exceptionList = methodDeclaration.findDescendantsOfType(ASTName.class); + List exceptionList = Collections.emptyList(); + ASTNameList nameList = methodDeclaration.getFirstChildOfType(ASTNameList.class); + if (nameList != null) { + exceptionList = nameList.findDescendantsOfType(ASTName.class); + } if (!exceptionList.isEmpty()) { evaluateExceptions(exceptionList, o); } diff --git a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strictexception/xml/SignatureDeclareThrowsException.xml b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strictexception/xml/SignatureDeclareThrowsException.xml index 8c5b3f4014..2d5a63c9e5 100644 --- a/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strictexception/xml/SignatureDeclareThrowsException.xml +++ b/pmd/src/test/resources/net/sourceforge/pmd/lang/java/rule/strictexception/xml/SignatureDeclareThrowsException.xml @@ -80,4 +80,19 @@ public class FooTest { } ]]> + + #913 SignatureDeclareThrowsException is raised twice + 1 + +