#626 SuppressWithNearbyCommentFilter ignores messageFormat

release_1.0
closed
nobody
None
5
2013-11-07
2010-11-12
Anonymous
No

It seems that the SuppressWithNearbyCommentFilter ignores the messageFormat configuration when the checkFormat is supplied.
In com.puppycrawl.tools.checkstyle.filters.SuppressWithNearbyCommentFilter.Tag.isMatch(AuditEvent) true is returned when the check matches without even checking if the message is also supplied and if the message matches.

Looking at this example:

<module name="SuppressWithNearbyCommentFilter">
    <property name="commentFormat" value="Ok to catch (\w+) here"/>
    <property name="checkFormat" value="IllegalCatchCheck"/>
    <property name="messageFormat" value="$1"/>
    <property name="influenceFormat" value="-1"/>
</module>

I would expect to be able to write Ok to catch Throwable here and suppress only Throwable catch messages but it supresses also Exception and Throwable since the message is not checked.

Discussion

  • Roman Ivanov
    Roman Ivanov
    2013-11-05

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -2,11 +2,14 @@
     In com.puppycrawl.tools.checkstyle.filters.SuppressWithNearbyCommentFilter.Tag.isMatch(AuditEvent) true is returned when the check matches without even checking if the message is also supplied and if the message matches.
    
     Looking at this example:
    +
    +~~~~~~
     <module name="SuppressWithNearbyCommentFilter">
         <property name="commentFormat" value="Ok to catch (\w+) here"/>
         <property name="checkFormat" value="IllegalCatchCheck"/>
         <property name="messageFormat" value="$1"/>
         <property name="influenceFormat" value="-1"/>
     </module>
    +~~~~~~
    
     I would expect to be able to write Ok to catch Throwable here and suppress only Throwable catch messages but it supresses also Exception and Throwable since the message is not checked.
    
    • Group: --> release_1.0
     
  • Roman Ivanov
    Roman Ivanov
    2013-11-07

    • status: open --> closed
     
  • Roman Ivanov
    Roman Ivanov
    2013-11-07

    eclipse-cs 5.6 fows fine on code:
    } catch (Exception e) { //Ok to catch Exception here
    throw new RuntimeException(e);
    }