forked from phoedos/pmd
Merge branch 'pr-1097'
This commit is contained in:
@ -31,6 +31,7 @@ This is a bug fixing release.
|
||||
* [#1067](https://github.com/pmd/pmd/issues/1067): \[java] [6.3.0] PrematureDeclaration false-positive
|
||||
* java-design
|
||||
* [#824](https://github.com/pmd/pmd/issues/824): \[java] UseUtilityClass false positive when extending
|
||||
* [#1097](https://github.com/pmd/pmd/pull/1097): \[java] False negative in AvoidThrowingRawExceptionTypes
|
||||
* java-performance
|
||||
* [#1098](https://github.com/pmd/pmd/pull/1098): \[java] Simplify LongInstantiation, IntegerInstantiation, ByteInstantiation, and ShortInstantiation using type resolution
|
||||
|
||||
|
@ -254,6 +254,7 @@ public class Foo {
|
||||
since="1.8"
|
||||
message="Avoid throwing raw exception types."
|
||||
class="net.sourceforge.pmd.lang.rule.XPathRule"
|
||||
typeResolution="true"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_design.html#avoidthrowingrawexceptiontypes">
|
||||
<description>
|
||||
Avoid throwing certain exception types. Rather than throw a raw RuntimeException, Throwable,
|
||||
@ -266,13 +267,13 @@ Exception, or Error, use a subclassed exception or error instead.
|
||||
<![CDATA[
|
||||
//ThrowStatement//AllocationExpression
|
||||
/ClassOrInterfaceType[
|
||||
(@Image='Throwable' and count(//ImportDeclaration/Name[ends-with(@Image,'Throwable')]) = 0)
|
||||
typeof(@Image, 'java.lang.Throwable', 'Throwable')
|
||||
or
|
||||
(@Image='Exception' and count(//ImportDeclaration/Name[ends-with(@Image,'Exception')]) = 0)
|
||||
typeof(@Image, 'java.lang.Exception', 'Exception')
|
||||
or
|
||||
(@Image='Error' and count(//ImportDeclaration/Name[ends-with(@Image,'Error')]) = 0)
|
||||
typeof(@Image, 'java.lang.Error', 'Error')
|
||||
or
|
||||
( @Image='RuntimeException' and count(//ImportDeclaration/Name[ends-with(@Image,'RuntimeException')]) = 0)
|
||||
typeof(@Image, 'java.lang.RuntimeException', 'RuntimeException')
|
||||
]
|
||||
]]>
|
||||
</value>
|
||||
|
@ -54,6 +54,20 @@ public class PmdTest {
|
||||
cause = new Throwable();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>False negative when importing another exception</description>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
import java.io.IOException;
|
||||
|
||||
public class Foo {
|
||||
|
||||
public void bar() {
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
</test-data>
|
||||
|
Reference in New Issue
Block a user