Please use the Apache issue tracking system for new NetBeans issues ( !!
Bug 270934 - formatting if clause with single code line and commentary breaks code
formatting if clause with single code line and commentary breaks code
Product: java
Classification: Unclassified
Component: Refactoring
PC Other
: P2 (vote)
: Dev
Assigned To: Dusan Balek
Depends on:
  Show dependency treegraph
Reported: 2017-06-22 20:21 UTC by Maksim Khramov
Modified: 2017-09-03 02:50 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT

Proposed change (1.38 KB, patch)
2017-08-07 06:17 UTC, Svata Dedic
Details | Diff
Proposed changes (9.81 KB, patch)
2017-08-07 13:31 UTC, Svata Dedic
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maksim Khramov 2017-06-22 20:21:11 UTC
Product Version: NetBeans IDE Dev (Build 201705310001)
Java: 1.8.0_131; Java HotSpot(TM) 64-Bit Server VM 25.131-b11

Steps to reproduce:
try to format next two code lines:

            System.out.println("true"); // TODO code application logic here

IDE adds opening bracket but closing bracket is missing
Comment 1 Svata Dedic 2017-08-04 14:36:13 UTC
Should be already fixed as part of issues #258227, #260880, see
Comment 2 Svata Dedic 2017-08-04 14:37:51 UTC
oops, sorry. Commented on incorrect issue.
Comment 3 Svata Dedic 2017-08-04 14:49:07 UTC
One must select the 2nd line up to the end, but NOT INCLUDING end of line (go to 1st line, then SHIFT-down, SHIFT-end) in order to produce the defect. If the 2nd line is selected including the (invisible) line terminator (2x SHIFT-down), the closing brace is inserted, although with bad indentation.
Comment 4 Svata Dedic 2017-08-07 06:16:14 UTC
In the reformatter, if formatting checks if the whole IfTree is enclosed in the formatted region. With the sample code, the if statement ends (end position is offset past last character of the statement) at the same offset as the selection (past the last character on the line).

Dusane, please review the diff.
Comment 5 Svata Dedic 2017-08-07 06:17:04 UTC
Created attachment 164906 [details]
Proposed change

Just < to <= change.
Comment 6 Svata Dedic 2017-08-07 10:09:33 UTC
oops ;) disregard the last message. Wrongly tested, I'll give it yet another try -- if I fail, I'll reassign.
Comment 7 Svata Dedic 2017-08-07 13:31:04 UTC
Created attachment 164908 [details]
Proposed changes

"end of node" is computed incl. possible trailing comments and whitespaces as the end of the last statement's line - because closing brace is added on a separate line. If the newline is not part of the formatting (selection till end of the line), the added closing brace (on the line following the selection) will be filtered out of the diff, and braces become unballanced.

the same issue is in do-while, while and for loops.
Comment 8 Dusan Balek 2017-09-01 11:50:11 UTC
Fixed in jet-main. Thanks for the patch.
Comment 9 Quality Engineering 2017-09-03 02:50:35 UTC
Integrated into 'main-silver', will be available in build *201709030001* on (upload may still be in progress)

User: Dusan Balek <>
Log: Issue #270934 - formatting if clause with single code line and commentary breaks code - fixed.

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo