Since Checkstyle 8.22
name | description | type | default value | since |
---|---|---|---|---|
allowWhenNoBraceAfterSemicolon | Allow unnecessary semicolon if closing parenthesis is not on the same line. | boolean | true |
8.22 |
To configure the check:
<module name="Checker"> <module name="TreeWalker"> <module name="UnnecessarySemicolonInTryWithResources"/> </module> </module>
Example of violations
class Example1 { void method() throws IOException { try (Reader r1 = new PipedReader();) {} // violation, 'Unnecessary semicolon' try (Reader r4 = new PipedReader(); Reader r5 = new PipedReader() ;) {} // violation, 'Unnecessary semicolon' try (Reader r6 = new PipedReader(); Reader r7 = new PipedReader(); // ok, closing parenthesis is not on the same line ) {} } }
To configure the check to detect unnecessary semicolon if closing parenthesis is not on the same line
<module name="Checker"> <module name="TreeWalker"> <module name="UnnecessarySemicolonInTryWithResources"> <property name="allowWhenNoBraceAfterSemicolon" value="false"/> </module> </module> </module>
Example of exclusion
class Example2 { void method() throws IOException { try (Reader r1 = new PipedReader();) {} // violation, 'Unnecessary semicolon' try (Reader r4 = new PipedReader(); Reader r5 = new PipedReader() ;) {} // violation, 'Unnecessary semicolon' try (Reader r6 = new PipedReader(); Reader r7 = new PipedReader(); // violation, 'Unnecessary semicolon' ) {} } }
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
com.puppycrawl.tools.checkstyle.checks.coding