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 onJDK-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
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
[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
- relates to
-
JDK-8230345 LineNumberReader.ready() can return true despite read() blocking
-
- Open
-
-
JDK-8230342 LineNumberReader.getLineNumber() returns inconsistent results after EOF
-
- Resolved
-
-
JDK-8230344 LineNumberReader.skipLF is not considered by all methods
-
- Open
-