pmd: fixed #913 SignatureDeclareThrowsException is raised twice

This commit is contained in:
Andreas Dangel
2013-01-23 21:44:32 +01:00
parent cb9861dd1f
commit e0b7f6f17c
3 changed files with 23 additions and 1 deletions

View File

@ -1,6 +1,7 @@
???? ??, 2012 - 5.0.2: ???? ??, 2012 - 5.0.2:
Fixed bug 878: False positive: UnusedFormalParameter for abstract methods 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 1012: False positive: Useless parentheses.
Fixed bug 1026: PMD doesn't handle 'value =' in SuppressWarnings annotation Fixed bug 1026: PMD doesn't handle 'value =' in SuppressWarnings annotation
Fixed bug 1037: Facing a showstopper issue in PMD Report Class (report listeners) Fixed bug 1037: Facing a showstopper issue in PMD Report Class (report listeners)

View File

@ -1,5 +1,6 @@
package net.sourceforge.pmd.lang.java.rule.strictexception; package net.sourceforge.pmd.lang.java.rule.strictexception;
import java.util.Collections;
import java.util.List; import java.util.List;
import net.sourceforge.pmd.lang.ast.Node; 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.ASTImportDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTName; import net.sourceforge.pmd.lang.java.ast.ASTName;
import net.sourceforge.pmd.lang.java.ast.ASTNameList;
import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule;
/** /**
@ -46,7 +48,11 @@ public class SignatureDeclareThrowsExceptionRule extends AbstractJavaRule {
return super.visit(methodDeclaration, o); return super.visit(methodDeclaration, o);
} }
List<ASTName> exceptionList = methodDeclaration.findDescendantsOfType(ASTName.class); List<ASTName> exceptionList = Collections.emptyList();
ASTNameList nameList = methodDeclaration.getFirstChildOfType(ASTNameList.class);
if (nameList != null) {
exceptionList = nameList.findDescendantsOfType(ASTName.class);
}
if (!exceptionList.isEmpty()) { if (!exceptionList.isEmpty()) {
evaluateExceptions(exceptionList, o); evaluateExceptions(exceptionList, o);
} }

View File

@ -80,4 +80,19 @@ public class FooTest {
} }
]]></code> ]]></code>
</test-code> </test-code>
<test-code>
<description>#913 SignatureDeclareThrowsException is raised twice</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class BugSignature {
public void record() {
SwingWorker worker = new SwingWorker() {
protected String construct() throws Exception {
//
}
};
}
}
]]></code>
</test-code>
</test-data> </test-data>