Since Checkstyle 8.22
Checks if unnecessary semicolon is used in last resource declaration.
name | description | type | default value | since |
---|---|---|---|---|
allowWhenNoBraceAfterSemicolon | Allow unnecessary semicolon if closing paren 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 A { void method() throws IOException { try(Reader r1 = new PipedReader();){} // violation try(Reader r4 = new PipedReader();Reader r5 = new PipedReader() ;){} // violation try(Reader r6 = new PipedReader(); Reader r7 = new PipedReader(); ){} } }
To configure the check to detect unnecessary semicolon if closing paren is not on same line
<module name="Checker"> <module name="TreeWalker"> <module name="UnnecessarySemicolonInTryWithResources"> <property name="allowWhenNoBraceAfterSemicolon" value="false"/> </module> </module> </module>
Example of exclusion
class A { void method() throws IOException { try(Reader r1 = new PipedReader();){} // violation try(Reader r6 = new PipedReader(); Reader r7 = new PipedReader(); // violation ){} } }
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