[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:
Juan Martín Sotuyo Dodero
2017-06-21 23:52:05 -03:00
parent bede603fb3
commit eda54ae86a
2 changed files with 19 additions and 0 deletions

View File

@ -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[

View File

@ -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>