com.puppycrawl.tools.checkstyle.meta.checks.coding.AvoidDoubleBraceInitializationCheck.xml Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of checkstyle Show documentation
Show all versions of checkstyle Show documentation
Checkstyle is a development tool to help programmers write Java code
that adheres to a coding standard
<?xml version="1.0" encoding="UTF-8"?> <checkstyle-metadata> <module> <check fully-qualified-name="com.puppycrawl.tools.checkstyle.checks.coding.AvoidDoubleBraceInitializationCheck" name="AvoidDoubleBraceInitialization" parent="com.puppycrawl.tools.checkstyle.TreeWalker"> <description><p> Detects double brace initialization. </p> <p> Rationale: Double brace initialization (set of <a href="https://docs.oracle.com/javase/specs/jls/se12/html/jls-8.html#jls-8.6"> Instance Initializers</a> in class body) may look cool, but it is considered as anti-pattern and should be avoided. This is also can lead to a hard-to-detect memory leak, if the anonymous class instance is returned outside and other object(s) hold reference to it. Created anonymous class is not static, it holds an implicit reference to the outer class instance. See this <a href="https://blog.jooq.org/dont-be-clever-the-double-curly-braces-anti-pattern/"> blog post</a> and <a href="https://www.baeldung.com/java-double-brace-initialization"> article</a> for more details. Check ignores any comments and semicolons in class body. </p></description> <message-keys> <message-key key="avoid.double.brace.init"/> </message-keys> </check> </module> </checkstyle-metadata>