RFR: 8180276: JTextPane getText return extra when mixed with methods of Document [v5]

Tejesh R duke at openjdk.java.net
Mon Apr 11 10:28:59 UTC 2022


On Mon, 11 Apr 2022 10:10:07 GMT, Alexey Ivanov <aivanov at openjdk.org> wrote:

> > > What happens if you add `\r` to an arbitrary location in text?
> > > What happens if you read in such a text?
> > 
> > 
> > It doesn't matter, since the data is appended only if '\n' is present when EndofLine is '\r\n'......
> 
> I'm not as sure… Well, yes, the text will be written out like expected and `\r` character will be preserved. Yet when such a text will be read in, the stranded `\r` will be converted to `\n` which will create an unexpected line break. Or am I wrong?

In `read(Reader in, Document doc, int pos)`, of DefaultEditorKit class, the logic states this 
`
        // Read in a block at a time, mapping \r\n to \n, as well as single
        // \r's to \n's. If a \r\n is encountered, \r\n will be set as the
        // newline string for the document, if \r is encountered it will
        // be set as the newline character, otherwise the newline property
        // for the document will be removed.
`

-------------

PR: https://git.openjdk.java.net/jdk/pull/8122



More information about the client-libs-dev mailing list