Skip to content

Commit

Permalink
Fixes sevntu-checkstyle#82. EitherLogOrThrowCheck was introduced.
Browse files Browse the repository at this point in the history
  • Loading branch information
baratali committed Aug 27, 2013
1 parent d8d56e6 commit 63196ba
Show file tree
Hide file tree
Showing 7 changed files with 828 additions and 0 deletions.
Expand Up @@ -91,3 +91,8 @@ UnnecessaryParenthesesExtended.name = Unnecessary Parentheses Extended
UnnecessaryParenthesesExtended.ignoreCalculationOfBooleanVariables = Cancel validation setups of unnecessary parentheses in Boolean computations.
UnnecessaryParenthesesExtended.ignoreCalculationOfBooleanVariablesWithReturn = Cancel validation setups of unnecessary parentheses in Boolean computations with return state.
UnnecessaryParenthesesExtended.ignoreCalculationOfBooleanVariablesWithAssert = Cancel validation setups of unnecessary parentheses in Boolean computations with assert state.
EitherLogOrThrowCheck.desc = <p>Detects cases when in catch clause programmer logs exception's stack trace and throws same(or derived) exception again.</p><p><b>Examples:</b><pre>catch (NoSuchMethodException e) {\n\tLOG.error("Message", e);\n\tthrow e;\n}</pre><b>or</b><pre>catch (NoSuchMethodException e) {\n\tLOG.error("Message", e);\n\tthrow new MyServiceException("AnotherMessage", e);\n}</pre></p><p>Logging and throwing results in multiple log messages for a single problem in the code, and makes life hell for the support engineer who is trying to dig through the logs.</p>
EitherLogOrThrowCheck.name = Either log exception or throw exception.
EitherLogOrThrowCheck.loggerFullyQualifiedClassName = Logger full class name. Example: "org.slf4j.Logger".
EitherLogOrThrowCheck.loggingMethodNames = Logger method names separated with commas. Example: "error,warn".
Expand Up @@ -211,6 +211,17 @@
<message-key key="unnecessary.paren.return" />
<message-key key="unnecessary.paren.string" />
</rule-metadata>

<rule-metadata name="%EitherLogOrThrowCheck.name" internal-name="EitherLogOrThrowCheck" parent="TreeWalker">
<alternative-name internal-name="com.github.sevntu.checkstyle.checks.coding.EitherLogOrThrowCheck" />
<description>%EitherLogOrThrowCheck.desc</description>
<property-metadata name="loggerFullyQualifiedClassName" datatype="String" default-value="">
<description>%EitherLogOrThrowCheck.loggerFullyQualifiedClassName</description>
</property-metadata>
<property-metadata name="loggingMethodNames" datatype="String" default-value="">
<description>%EitherLogOrThrowCheck.loggerMethodNames</description>
</property-metadata>
</rule-metadata>

<!-- DOES NOT WORK PROPERLY
<rule-metadata name="%NoMainMethodInAbstractClass.name" internal-name="NoMainMethodInAbstractClass" parent="TreeWalker">
Expand Down
7 changes: 7 additions & 0 deletions sevntu-checks/.checkstyle
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<fileset-config file-format-version="1.2.0" simple-config="true" sync-formatter="false">
<fileset name="all" enabled="true" check-config-name="Checkstyle" local="false">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
</fileset-config>

0 comments on commit 63196ba

Please sign in to comment.