[java] EmptyCatchBlock may ignore blocks based on exception name
- Allow the developer to setup a regular expression for exception names to be ignored by the rule. - Fixes #413
This commit is contained in:
@ -30,10 +30,12 @@ or reported.
|
|||||||
[FormalParameter/Type/ReferenceType
|
[FormalParameter/Type/ReferenceType
|
||||||
/ClassOrInterfaceType[@Image != 'InterruptedException' and @Image != 'CloneNotSupportedException']
|
/ClassOrInterfaceType[@Image != 'InterruptedException' and @Image != 'CloneNotSupportedException']
|
||||||
]
|
]
|
||||||
|
[FormalParameter/VariableDeclaratorId[not(matches(@Image, $allowExceptionNameRegex))]]
|
||||||
]]>
|
]]>
|
||||||
</value>
|
</value>
|
||||||
</property>
|
</property>
|
||||||
<property name="allowCommentedBlocks" type="Boolean" description="Empty blocks containing comments will be skipped" value="false"/>
|
<property name="allowCommentedBlocks" type="Boolean" description="Empty blocks containing comments will be skipped" value="false"/>
|
||||||
|
<property name="allowExceptionNameRegex" type="String" description="Empty blocks catching exceptions with names matching this regular expression will be skipped" value="^$"/>
|
||||||
</properties>
|
</properties>
|
||||||
<example>
|
<example>
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
|
@ -167,4 +167,21 @@ Javadoc comment is not OK
|
|||||||
</test-code>
|
</test-code>
|
||||||
|
|
||||||
<!-- END Commented blocks -->
|
<!-- END Commented blocks -->
|
||||||
|
<test-code>
|
||||||
|
<description><![CDATA[
|
||||||
|
Allow to ignore exceptions by name
|
||||||
|
]]></description>
|
||||||
|
<rule-property name="allowExceptionNameRegex">^(ignored|expected)$</rule-property>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code><![CDATA[
|
||||||
|
public class Foo {
|
||||||
|
void foo() {
|
||||||
|
try {
|
||||||
|
} catch (NullPointerException expected) {
|
||||||
|
} catch (IllegalArgumentException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]]></code>
|
||||||
|
</test-code>
|
||||||
</test-data>
|
</test-data>
|
||||||
|
Reference in New Issue
Block a user