[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
|
||||
/ClassOrInterfaceType[@Image != 'InterruptedException' and @Image != 'CloneNotSupportedException']
|
||||
]
|
||||
[FormalParameter/VariableDeclaratorId[not(matches(@Image, $allowExceptionNameRegex))]]
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
<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>
|
||||
<example>
|
||||
<![CDATA[
|
||||
|
@ -167,4 +167,21 @@ Javadoc comment is not OK
|
||||
</test-code>
|
||||
|
||||
<!-- 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>
|
||||
|
Reference in New Issue
Block a user