8235792: LineNumberReader.getLineNumber() behavior is inconsistent with respect to EOF

Reviewed-by: alanb, darcy, rriggs
This commit is contained in:
Brian Burkhalter 2020-08-05 11:40:07 -07:00
parent 339016a0f2
commit 3ea5fdc9ac
3 changed files with 136 additions and 24 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -302,6 +302,8 @@ public class BufferedReader extends Reader {
* (EOF).
*
* @param ignoreLF If true, the next '\n' will be skipped
* @param term Output: Whether a line terminator was encountered
* while reading the line; may be {@code null}.
*
* @return A String containing the contents of the line, not including
* any line-termination characters, or null if the end of the
@ -311,13 +313,14 @@ public class BufferedReader extends Reader {
*
* @throws IOException If an I/O error occurs
*/
String readLine(boolean ignoreLF) throws IOException {
String readLine(boolean ignoreLF, boolean[] term) throws IOException {
StringBuilder s = null;
int startChar;
synchronized (lock) {
ensureOpen();
boolean omitLF = ignoreLF || skipLF;
if (term != null) term[0] = false;
bufferLoop:
for (;;) {
@ -344,6 +347,7 @@ public class BufferedReader extends Reader {
for (i = nextChar; i < nChars; i++) {
c = cb[i];
if ((c == '\n') || (c == '\r')) {
if (term != null) term[0] = true;
eol = true;
break charLoop;
}
@ -389,7 +393,7 @@ public class BufferedReader extends Reader {
* @see java.nio.file.Files#readAllLines
*/
public String readLine() throws IOException {
return readLine(false);
return readLine(false, null);
}
/**