JDK-8230343 : LineNumberReader.read(char[] cbuf, int off, int len) sets skipLF
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 11,13,14
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-08-27
  • Updated: 2019-08-30
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 :  
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
Only LineNumberReader.read() compresses \r\n to \n. For its other methods this behavior is not documented. This is also confirmed by this ([0]) evaluation comment on JDK-6498795. However, read(char[] cbuf, int off, int len) actually sets skipLF and therefore affects read()'s behavior. Expected would be that read(char[], ...) only clears skipLF and then uses a local variable to track line terminators.

[0] https://bugs.openjdk.java.net/browse/JDK-6498795?focusedCommentId=12139576#comment-12139576


---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.StringReader;

public class ReadSkipLfTest {
    public static void main(String[] args) throws IOException {
        String string = "\r\n";
        LineNumberReader reader = new LineNumberReader(new StringReader(string));
        
        // read(char[]) is not described as compressing \r\n, so it should just read 
        // \r and then subsequent read() should read \n
        reader.read(new char[1]);
        
        if (reader.read() == -1) {
            throw new AssertionError("Expected \\n");
        }
    }
}

---------- END SOURCE ----------

FREQUENCY : always



Comments
To reproduce the issue , run the attached test case : JDK 11.0.4 - Fail JDK 13-ea+32 - Fail JDK 14-ea+8 - Fail Output: Exception in thread "main" java.lang.AssertionError: Expected \n at ReadSkipLfTest.main(ReadSkipLfTest.java:15)
29-08-2019