mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
48 lines
1.5 KiB
HTML
48 lines
1.5 KiB
HTML
<html>
|
|
<body>
|
|
Reports any <code>if</code>, <code>while</code>, <code>do</code>, or <code>for</code> statements without braces.
|
|
Some code styles, e.g. the <a href="https://google.github.io/styleguide/javaguide.html">Google Java Style guide</a>,
|
|
require braces for all control statements.
|
|
<p>
|
|
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.
|
|
<p>
|
|
It's likely the <a href="https://www.imperialviolet.org/2014/02/22/applebug.html">goto fail vulnerability</a> 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.</p>
|
|
<p>Example:</p>
|
|
<pre><code>
|
|
class Strange {
|
|
void x(boolean one, boolean two) {
|
|
if(one)
|
|
if(two)
|
|
foo();
|
|
else
|
|
bar();
|
|
}
|
|
|
|
void foo() {}
|
|
void bar() {}
|
|
}
|
|
</code></pre>
|
|
<p>The quick-fix wraps the statement body with braces:</p>
|
|
<pre><code>
|
|
class Strange {
|
|
void x(boolean one, boolean two) {
|
|
if(one) {
|
|
if(two) {
|
|
foo();
|
|
} else {
|
|
bar();
|
|
}
|
|
}
|
|
}
|
|
|
|
void foo() {}
|
|
void bar() {}
|
|
}
|
|
</code></pre>
|
|
</body>
|
|
</html> |