How various line separators (EOLs) are handled?
NetBeans editor respects the line separator used in an existing file. It reads the file into an editor document instance in the following way:
- First line of the file is read and the line separator type is determined - it is expected to be one of
- "\n" (LF)- Unix
- "\r" (CR)- Mac
- "\r\n" (CRLF) - Windows
- The line separator type is remembered in the document instance for future save operation.
- All the lines in the file are read and their line separator (regardless of what type it is) is translated to "\n" that is the only line separator type that the editor is able to work with.
- Upon save operation each "\n" in the document is translated into the remembered line separator type.
Note: If there would be a mixture of line separators of multiple types throughout the file then only the line separator type from the original first line will be used upon save.
For new files (constructed from templates) the editor uses platform-default line separator.
Currently there are no additional options for handling line separators.
When working with CVS across the Windows and Unix platforms it may happen that the line separator will become garbled.
If a file is checked out on Windows platform then the CVS client will replace repository-natural LF line separators into CRLFs. If this file is then checked-in on Unix platform then the CRLFs will not be translated back to LFs because the Unix CVS client expects that the file was checked out on Unix originally and thus no translation is necessary. So then CRLFs will physically be stored in the CVS repository which will lead to problems. If such file is now checked out on Windows platform then the CVS client again translates LFs to CRLFs which will lead to line separators being CRCRLF.
When reading CRCRLF line separator sequence the NetBeans editor sees a Mac CR line separator immediately followed by an empty line with Windows CRLF separator at the end so it will create two "\n\n" line separators for such sequence. Visually the document will have an extra empty line after each line of text.
Solution to this problem is to eliminate the primary problem - do not commit the file on Unix that was checked-out on Windows originally. If this already happened then e.g. checkout the file with CRLFs on Unix and open it in an external editor that determines Windows CRLF sequences properly and is able to write back LFs. For example in ViM (Vi Improved) :set ff=unix may be used.
Applies to: All NetBeans versions