8230342: LineNumberReader.getLineNumber() returns inconsistent results after EOF

Reviewed-by: rriggs, dfuchs
This commit is contained in:
Brian Burkhalter 2019-09-11 12:32:01 -07:00
parent c920b4a5c0
commit 4285853d91
3 changed files with 66 additions and 9 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2019, 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 {
*
* @exception IOException If an I/O error occurs
*/
String readLine(boolean ignoreLF) throws IOException {
String readLine(boolean ignoreLF, boolean[] term) throws IOException {
StringBuffer 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);
}
/**