forked from phoedos/pmd
Merge branch 'pr-455'
This commit is contained in:
pmd-java/src
main/java/net/sourceforge/pmd/lang/java
rule/strictexception
typeresolution/rules
test/resources/net/sourceforge/pmd/lang/java/rule
strictexception/xml
typeresolution/xml
src/site/markdown/overview
@ -8,6 +8,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnnotation;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTCompilationUnit;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration;
|
||||
@ -51,6 +52,15 @@ public class SignatureDeclareThrowsExceptionRule extends AbstractJavaRule {
|
||||
if (methodDeclaration.getMethodName().startsWith("test")) {
|
||||
return super.visit(methodDeclaration, o);
|
||||
}
|
||||
|
||||
// Ignore overridden methods, the issue should be marked on the method definition
|
||||
final List<ASTAnnotation> methodAnnotations = methodDeclaration.jjtGetParent().findChildrenOfType(ASTAnnotation.class);
|
||||
for (final ASTAnnotation annotation : methodAnnotations) {
|
||||
final ASTName annotationName = annotation.getFirstDescendantOfType(ASTName.class);
|
||||
if (annotationName.hasImageEqualTo("Override") || annotationName.hasImageEqualTo("java.lang.Override")) {
|
||||
return super.visit(methodDeclaration, o);
|
||||
}
|
||||
}
|
||||
|
||||
List<ASTName> exceptionList = Collections.emptyList();
|
||||
ASTNameList nameList = methodDeclaration.getFirstChildOfType(ASTNameList.class);
|
||||
|
@ -7,6 +7,7 @@ package net.sourceforge.pmd.lang.java.typeresolution.rules;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnnotation;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceType;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTConstructorDeclaration;
|
||||
@ -113,6 +114,15 @@ public class SignatureDeclareThrowsException extends AbstractJavaRule {
|
||||
if (junitImported && isAllowedMethod(methodDeclaration)) {
|
||||
return super.visit(methodDeclaration, o);
|
||||
}
|
||||
|
||||
// Ignore overridden methods, the issue should be marked on the method definition
|
||||
final List<ASTAnnotation> methodAnnotations = methodDeclaration.jjtGetParent().findChildrenOfType(ASTAnnotation.class);
|
||||
for (final ASTAnnotation annotation : methodAnnotations) {
|
||||
final ASTName annotationName = annotation.getFirstDescendantOfType(ASTName.class);
|
||||
if (annotationName.hasImageEqualTo("Override") || annotationName.hasImageEqualTo("java.lang.Override")) {
|
||||
return super.visit(methodDeclaration, o);
|
||||
}
|
||||
}
|
||||
|
||||
checkExceptions(methodDeclaration, o);
|
||||
|
||||
|
@ -103,4 +103,16 @@ public class BugSignature {
|
||||
public class UnmodifiableList<T> implements @Readonly List<@Readonly T> {}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#350 allow throws exception when overriding a method defined elsewhere</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class BugSignature implements LousyInterface {
|
||||
@Override
|
||||
public void record() throws Exception {
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
@ -151,4 +151,16 @@ public class Foo {
|
||||
public class UnmodifiableList<T> implements @Readonly List<@Readonly T> {}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>#350 allow throws exception when overriding a method defined elsewhere</description>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
public class BugSignature implements LousyInterface {
|
||||
@Override
|
||||
public void record() throws Exception {
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
@ -39,7 +39,7 @@ Fields using generics are still Work in Progress, but we expect to fully support
|
||||
* The ruleset java-junit now properly detects JUnit5, and rules are being adapted to the changes on it's API.
|
||||
This support is, however, still incomplete. Let us know of any uses we are still missing on the [issue tracker](https://github.com/pmd/pmd/issues)
|
||||
|
||||
* The Java rule `EmptyTryBlock` (ruleset java-empty) now allows empty blocks when usin try-with-resources.
|
||||
* The Java rule `EmptyTryBlock` (ruleset java-empty) now allows empty blocks when using try-with-resources.
|
||||
|
||||
### Fixed Issues
|
||||
|
||||
@ -67,6 +67,10 @@ Fields using generics are still Work in Progress, but we expect to fully support
|
||||
* [#428](https://github.com/pmd/pmd/issues/428): \[java] PMD requires public modifier on JUnit 5 test
|
||||
* java-logging:
|
||||
* [#365](https://github.com/pmd/pmd/issues/365): \[java] InvalidSlf4jMessageFormat does not handle inline incrementation of arguments
|
||||
* java-strictexceptions
|
||||
* [#350](https://github.com/pmd/pmd/issues/350): \[java] Throwing Exception in method signature is fine if the method is overriding or implementing something
|
||||
* java-typeresolution
|
||||
* [#350](https://github.com/pmd/pmd/issues/350): \[java] Throwing Exception in method signature is fine if the method is overriding or implementing something
|
||||
* java-unnecessary
|
||||
* [#421](https://github.com/pmd/pmd/issues/421): \[java] UnnecessaryFinalModifier final in private method
|
||||
* jsp
|
||||
|
Reference in New Issue
Block a user