Merge branch 'pr/3736' into 7.0.x

This commit is contained in:
Clément Fournier committed 2022-01-15 17:10:29 +01:00
commit fe719f88bf
4 files changed
+19 -11

No files matched your search

+1 -1
View File
@@ -122,7 +122,7 @@
<rule ref="category/java/design.xml/AvoidCatchingGenericException"/>
<!-- <rule ref="category/java/design.xml/AvoidDeeplyNestedIfStmts"/> -->
<rule ref="category/java/design.xml/AvoidRethrowingException"/>
<!-- <rule ref="category/java/design.xml/AvoidThrowingNewInstanceOfSameException"/> -->
<rule ref="category/java/design.xml/AvoidThrowingNewInstanceOfSameException"/>
<rule ref="category/java/design.xml/AvoidThrowingNullPointerException"/>
<!-- <rule ref="category/java/design.xml/AvoidThrowingRawExceptionTypes"/> -->
<rule ref="category/java/design.xml/AvoidUncheckedExceptionsInSignatures"/>
@@ -163,15 +163,11 @@ code size and runtime complexity.
<property name="xpath">
<value>
<![CDATA[
//CatchStatement[
count(Block/BlockStatement/Statement) = 1
and
FormalParameter/Type/ReferenceType/ClassOrInterfaceType/@Image = Block/BlockStatement/Statement/ThrowStatement/Expression/PrimaryExpression/PrimaryPrefix/AllocationExpression/ClassOrInterfaceType/@Image
and
count(Block/BlockStatement/Statement/ThrowStatement/Expression/PrimaryExpression/PrimaryPrefix/AllocationExpression/Arguments/ArgumentList/Expression) = 1
and
FormalParameter/VariableDeclaratorId = Block/BlockStatement/Statement/ThrowStatement/Expression/PrimaryExpression/PrimaryPrefix/AllocationExpression/Arguments/ArgumentList/Expression/PrimaryExpression/PrimaryPrefix/Name
]
//CatchClause
[count(Block/*) = 1]
[CatchParameter/ClassOrInterfaceType/@SimpleName = Block/ThrowStatement/ConstructorCall/ClassOrInterfaceType/@SimpleName]
[Block/ThrowStatement/ConstructorCall/ArgumentList/@Size = 1]
/Block/ThrowStatement/ConstructorCall
]]>
</value>
</property>
@@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.java.rule.design;
import net.sourceforge.pmd.testframework.PmdRuleTst;
@org.junit.Ignore("Rule has not been updated yet")
public class AvoidThrowingNewInstanceOfSameExceptionTest extends PmdRuleTst {
// no additional unit tests
}
@@ -7,6 +7,7 @@
<test-code>
<description>basic failure case</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>5</expected-linenumbers>
<code><![CDATA[
public class Foo {
void bar() {
@@ -16,6 +17,7 @@ public class Foo {
}
}
}
class SomeException extends Exception {}
]]></code>
</test-code>
@@ -32,12 +34,14 @@ public class Foo {
}
}
}
class SomeException extends Exception {}
]]></code>
</test-code>
<test-code>
<description>repackage cause as an instance of the same exception, failure</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>5</expected-linenumbers>
<code><![CDATA[
public class Foo {
void bar() {
@@ -47,6 +51,7 @@ public class Foo {
}
}
}
class SomeException extends Exception {}
]]></code>
</test-code>
@@ -62,12 +67,14 @@ public class Foo {
}
}
}
class SomeException extends Exception {}
]]></code>
</test-code>
<test-code>
<description>throw new instance of the same exception with the same message, failure</description>
<expected-problems>1</expected-problems>
<expected-linenumbers>5</expected-linenumbers>
<code><![CDATA[
public class Foo {
void bar() {
@@ -77,6 +84,7 @@ public class Foo {
}
}
}
class SomeException extends Exception {}
]]></code>
</test-code>
@@ -92,6 +100,7 @@ public class Foo {
}
}
}
class SomeException extends Exception {}
]]></code>
</test-code>
@@ -110,6 +119,8 @@ public class Foo {
}
}
}
class SomeException extends Exception {}
class OtherException extends Exception {}
]]></code>
</test-code>
@@ -128,6 +139,8 @@ public class Foo {
}
}
}
class SomeException extends Exception {}
class OtherException extends Exception {}
]]></code>
</test-code>
</test-data>