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 262762 - Saving a file changes its line separator
Summary: Saving a file changes its line separator
Status: NEW
Alias: None
Product: editor
Classification: Unclassified
Component: Actions/Menu/Toolbar (show other bugs)
Version: 8.2
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Assignee: Miloslav Metelka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-11 08:45 UTC by terje7601
Modified: 2016-08-02 09:21 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
example file for which this bug occurred (154 bytes, text/plain)
2016-08-02 09:21 UTC, terje7601
Details

Note You need to log in before you can comment on or make changes to this bug.
Description terje7601 2016-07-11 08:45:26 UTC
So the scenario is:
- I have a file with Unix EOLs
- I add a space in the file and save
- the EOLs have changed to Windows EOLs
- I quit NetBeans, clear its Cache directory, change the EOLs back to Unix-style & restart NetBeans
- again, I add a space in the file and save
- now the EOLs haven't changed and are still in Unix-style as expected

And the issue is that, at step 3, NetBeans changed the EOLs. What is expected is that, whenever NetBeans saves a file, it makes sure to do so with the same line separators as in the actual file.


Product Version: NetBeans IDE Dev (Build 201606240002)
Java: 1.8.0_91; Java HotSpot(TM) 64-Bit Server VM 25.91-b15
Runtime: Java(TM) SE Runtime Environment 1.8.0_91-b15
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
Comment 1 Miloslav Metelka 2016-07-11 12:42:10 UTC
NB editor scans a newline of the first line of the file to determine the line separator and then uses it for all lines when saving the file. Could you attach the problematic file or double-check that there's a Unix EOL on the first line too? What's extension of the file is it .java or anything else? Thanks.
Comment 2 terje7601 2016-07-12 06:30:00 UTC
The file was a .java file. I noticed git diff showed the whole file as modified, so I changed back to Unix EOL using Notepad++. Notepad++ always changes all EOLs - even if the file contains mixed EOLs - so I'm sure every line had the correct Unix EOL. However, NetBeans kept saving with Windows EOLs. Only after stopping, clearing NetBeans' cache and starting again, did it work correctly.

When the NB editor reads from a file, does it always read from the actual file on disk? Or is it possible that it reads from a cached version in memory or NetBeans' cache?
Comment 3 terje7601 2016-08-02 09:21:00 UTC
I just had this occur again: an .sql file with nothing but Unix EOLs, no \r character at all in the file. In attachment is the .sql file. However, as explained in the initial report, the file itself doesn't cause the issue: after restarting NetBeans, it works as expected with the exact same file and the EOLs aren't changed (note that I didn't clear the Cache directory this time).

PS: related to this, I filed bug 267397, so that I could at least detect this bug with the Diff view

Product Version: NetBeans IDE Dev (Build 201607110002)
Updates: Updates available
Java: 1.8.0_91; Java HotSpot(TM) 64-Bit Server VM 25.91-b15
Runtime: Java(TM) SE Runtime Environment 1.8.0_91-b15
System: Windows 7 version 6.1 running on amd64; Cp1252; en_US (nb)
Comment 4 terje7601 2016-08-02 09:21:56 UTC
Created attachment 161529 [details]
example file for which this bug occurred