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 223209 - Format on Save buggy for updating modified lines only
Summary: Format on Save buggy for updating modified lines only
Status: RESOLVED INVALID
Alias: None
Product: editor
Classification: Unclassified
Component: Formatting & Indentation (show other bugs)
Version: 7.3
Hardware: PC Windows 7
: P2 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-03 21:13 UTC by _ gtzabari
Modified: 2013-01-02 15:42 UTC (History)
0 users

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 _ gtzabari 2012-12-03 21:13:17 UTC
Product Version: NetBeans IDE Dev (Build 201212030001)
Java: 1.7.0_09; Java HotSpot(TM) 64-Bit Server VM 23.5-b02
Runtime: Java(TM) SE Runtime Environment 1.7.0_09-b05
System: Windows 7 version 6.1 running on amd64; Cp1252; en_CA (nb)
User directory: C:\Users\Gili\AppData\Roaming\NetBeans\dev
Cache directory: C:\Users\Gili\AppData\Local\NetBeans\Cache\dev

Format on Save sometimes leads to data loss, sometimes to incorrectly formatted results. Instead of filing separate bug reports (which is difficult to do since I don't remember which lines I modified), I suggest you (temporary) add code that formats the code twice:

1. Once only for modified lines.
2. Once for the entire file.

Compare the two. If they differ, automatically file a bug report with Exception Reporter. This will temporarily make this feature slower to use, but will speed up fixing it.

Because I've seen data loss as a result of this feature I've set the priority to P2.
Comment 1 Dusan Balek 2012-12-04 11:56:56 UTC
I don't think the proposed solution would work. In a majority of cases, even the valid result of reformatting the modified lines only would differ from the result of reformatting entire file (otherwise there is no need for the 'Reformat modified lines only' option at all).

So, if you are encountering a data loss, please, file a bug with the particular test case. Thanks.
Comment 2 _ gtzabari 2012-12-04 14:33:01 UTC
Out of curiosity, is there a technical way to make "reformat only modified lines" yield the same result as "reformat entire file"? Obviously the end-goal is "reformat entire file" but we want it to be faster. What context are you missing from "reformat only modified lines" which prevents you from making the two equivalent?
Comment 3 _ gtzabari 2012-12-28 15:25:25 UTC
I am reopening this issue for one last consideration: consider removing the "Reformat modified lines only" option.

I argue that, from a usability point of view, users never want results yielded by partial-formatting. I believe this option only exists for performance reasons, as a hack for the fact that full-reformatting is uncomfortably slow in many cases.

We should be fixing the underlying problem instead of trying to mask it. We should look at optimizing the algorithm (perhaps we can cache structures from previous reformat operations or scale across multiple cores).

I wouldn't mind Netbeans using more memory in exchange for better performance. Look, my system has 24GB of RAM. Netbeans decides to cap itself at 768MB. In systems like mine (with lots of free memory) Netbeans should be smart enough to use more RAM and substantially speed up common operations like code-reformatting.
Comment 4 Dusan Balek 2013-01-02 15:42:09 UTC
I think there is a stronger reason for the "Reformat modified lines only" option existence than performance - minimizing diffs for sources shared via VCS.

Consider a common scenario - a larger project shared via VCS across multiple developers using a variety of editors for coding their sources. For such project you simply cannot assume that all sources are always correctly formatted using the single code style. I don't think it is a good idea to bother these developers with the Exception Reporter popping up on every Ctrl-S (please note that in a majority of cases the result of partial-formatting would be correct but still different from the full-reformatting result).

Once again, if you are encountering any problem with partial-formatting, please, file a bug with the particular test case. Thanks.