Menu

#317 Incorrect indentation of nested if

2: Annoying
open-duplicate
nobody
5
2004-08-18
2004-08-18
No

Nested if statements without braces are auto-indented incorrectly:

class Test {
void test(int i) {
int j = -1;
if (i > 0)
if (i > 1)
j = 3;
else
j = 5;
}
}

The "else" should align with the inner "if" following the dangling-
else rule of Java syntax.

Discussion

  • Charles Reis

    Charles Reis - 2004-08-18
    • status: open --> open-duplicate
     
  • Charles Reis

    Charles Reis - 2004-08-18

    Logged In: YES
    user_id=429731

    FYI-- this is a duplicate of bug 627753, "Indent: nested, braceless if's /
    for's". There's already a discussion of it there, but the original efforts to
    fix it didn't get anywhere. (The catch is differentiating between this and
    method definitions without parsing for "if", "for", etc.)

    It would probably be best to continue discussion in only one of these
    reports, but I'll let the current developers decide which one.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.