JDK-8284773 : Clarify spec for DefaultEditorKit.EndOfLineStringProperty
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2022-04-12
  • Updated: 2022-04-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Description
Currently the spec for DefaultEditorKit.EndOfLineStringProperty says: "When reading a document if a CRLF is encountered a property with this name is added and the value will be "\r\n"." It is not clear.

In fact, the property value stores the line end. It is set when the file is read. When the file is saved, the the value of the 'EndOfLineStringProperty' property is used as the line break written to disk.
Comments
> "it is not clear" means "it is not clear what are the implications of this" - as > opposed to the sentence is hard to understand ? I meant both. Adding commas could make the sentence easier to parse. Rephrasing could make it clearer. It's a name of a document property. Its value determines the line break that is inserted when the document is written to a file. When the text is read from a file, this property is set on the document to the line break. At this time, both Linux and macOS use "\n" by default, only Windows uses "\r\n". Another question to answer would be about "\r" is the only line separator. It should be preserved but I haven't verified it yet. > So if the document is subsequently saved, and this property is set because CRLF > was used in the source document, the value (ie CRLF) is used as the line ending > in the saved document. Otherwise the default of "\n" (LF) is used." I wish it were as simple. Yet the implementation differs: if EndOfLineStringProperty is not set, the default is to use System.lineSeparator(). So the implications of handling new lines in Document model (AbstractDocument) as well as in EditorKit for reading and writing files should be clarified. These implications are described in DefaultEditorKit under Newlines section (which should be converted to a <h2> header with an anchor for easier linking). The description of EndOfLineStringProperty could then link to these details. The Document interface has a detailed overview of Swing text design. It could be expanded by adding a section on handling new lines. > Open question : what happens if \r\n is inserted by a user into the model ? As we saw in JDK-8180276 and its PR https://github.com/openjdk/jdk/pull/8122 the "\r" doesn't have special treatment if it's explicitly added into the text model. If the text is written to a file, "\r" is written as is. When such file is read, "\r" if not followed by "\n" is converted to "\n", the pair "\r\n" is converted to single "\n". For example, the sequence of "\r\r\n" in a file is converted by DefaultEditorKit to "\n\n" on Windows.
15-04-2022

"it is not clear" means "it is not clear what are the implications of this" - as opposed to the sentence is hard to understand ? I agree it could use some clarification so I'd go with adding just "The intent is to preserve CRLF line endings when re-writing a document which originally contained them". So if the document is subsequently saved, and this property is set because CRLF was used in the source document, the value (ie CRLF) is used as the line ending in the saved document. Otherwise the default of "\n" (LF) is used." Open question : what happens if \r\n is inserted by a user into the model ?
15-04-2022