Inspectopedia 2024.3 Help

Control flow statement without braces

Reports any if, while, do, or for statements without braces. Some code styles, e.g. the Google Java Style guide, require braces for all control statements.

When adding further statements to control statements without braces, it is important not to forget adding braces. When commenting out a line of code, it is also necessary to be more careful when not using braces, to not inadvertently make the next statement part of the control flow statement. Always using braces makes inserting or commenting out a line of code safer.

It's likely the goto fail vulnerability would not have happened, if an always use braces code style was used. Control statements with braces make the control flow easier to see, without relying on, possibly incorrect, indentation.

Example:

class Strange { void x(boolean one, boolean two) { if(one) if(two) foo(); else bar(); } void foo() {} void bar() {} }

The quick-fix wraps the statement body with braces:

class Strange { void x(boolean one, boolean two) { if(one) { if(two) { foo(); } else { bar(); } } } void foo() {} void bar() {} }

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

ControlFlowStatementWithoutBraces
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Code style issues

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.3, Qodana for JVM 2024.3,

Can be installed with plugin:

Java, 243.23126

Last modified: 03 December 2024