This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 252303 - Source format removes braces
Summary: Source format removes braces
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 8.1
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-08 15:55 UTC by cezariusz
Modified: 2016-04-27 13:28 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description cezariusz 2015-05-08 15:55:45 UTC
Product Version: NetBeans IDE Dev (Build 201505020001)
Java: 1.8.0_45; Java HotSpot(TM) 64-Bit Server VM 25.45-b02
Runtime: Java(TM) SE Runtime Environment 1.8.0_45-b14
System: Windows 7 version 6.1 running on amd64; UTF-8; pl_PL (nb)

Source format automatically removes braces from "else" statement with "if-else" inside. I'm aware that it doesn't change execution flow, but anyway it shouldn't happen.

Testcase:

    public void demo(boolean a, boolean b) {
        if (a) {
            if (b) {
                System.out.println("a AND b");
            } else {
                System.out.println("a AND NOT b");
            }
        } else {
            // a is false
            if (b) {
                System.out.println("NOT a AND b");
            } else {
                System.out.println("NOT a AND NOT b");
            }
        }
    }

After format:

    public void demo(boolean a, boolean b) {
        if (a) {
            if (b) {
                System.out.println("a AND b");
            } else {
                System.out.println("a AND NOT b");
            }
        } else // a is false
        if (b) {
            System.out.println("NOT a AND b");
        } else {
            System.out.println("NOT a AND NOT b");
        }
    }

The code after the format is harder to read and it's not fit our coding style.
Comment 1 cezariusz 2015-05-08 15:56:55 UTC
(In reply to cezariusz from comment #0)
> it's not fit our coding style.

I mean it doesn't follow our coding style.
Comment 2 Jiri Prox 2015-05-11 08:24:54 UTC
This behavior can be customized in Options -> Editor -> Formatting -> Braces -> Special If-else treatment
Comment 3 giancarlolongo 2016-01-05 14:11:29 UTC
(In reply to Jiri Prox from comment #2)
> This behavior can be customized in Options -> Editor -> Formatting -> Braces
> -> Special If-else treatment

If you deselect "Special If-else treatment" braces will not removed, but "else if" will be break into two lines.
This behaviour did not happen in past verions of NB, like v7: braces were never removed.
Comment 4 Svata Dedic 2016-04-27 13:28:19 UTC
Probably caused by http://hg.netbeans.org/jet-main/rev/4632127cda3e