Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8241020

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

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P4
    • Resolution: Approved
    • Fix Version/s: 16
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      medium
    • Compatibility Risk Description:
      This might cause a problem for code which does not expect the line number to be incremented by an EOS, i.e., which expects incrementing only for `\r`, `\n`, or `\r\n`.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Modify LineNumberReader to consider end-of-stream to be a line terminator.

      Problem

      LineNumberReader presently does not consider end-of-stream to be a line terminator, i.e, one of \r, \n, or \r\n. Thus for example for a stream such as

      line 1\n
      line 2\n
      line 3

      which ends without a line terminator, only two lines would be reported.

      Solution

      Modify LineNumberReader to consider end-of-stream to be a line terminator.

      Specification

      Modify the specification of LineNumberReader as follows.

      Class specification

      By default, line numbering begins at 0. This number increments at every line terminator as the data is read, and at the end of the stream if the last character in the stream is not a line terminator. This number can be changed with a call to setLineNumber(int). Note however, that setLineNumber(int) does not actually change the current position in the stream; it only changes the value that will be returned by getLineNumber().

      A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed, or any of the previous terminators followed by end of stream, or end of stream not preceded by another terminator.

      read() specification

      Read a single character. Line terminators are compressed into single newline ('\n') characters. The current line number is incremented whenever a line terminator is read, or when the end of the stream is reached and the last character in the stream is not a line terminator.

      read(char[],int,int) specification

      Read characters into a portion of an array. Line terminators are compressed into single newline ('\n') characters. The current line number is incremented whenever a line terminator is read, or when the end of the stream is reached and the last character in the stream is not a line terminator.

      readLine() specification

      Read a line of text. Line terminators are compressed into single newline ('\n') characters. The current line number is incremented whenever a line terminator is read, or when the end of the stream is reached and the last character in the stream is not a line terminator.

        Attachments

        1. webrev-8235792.zip
          158 kB
        2. webrev-8235792.zip
          157 kB
        3. webrev-8235792.zip
          156 kB

          Issue Links

            Activity

              People

              Assignee:
              bpb Brian Burkhalter
              Reporter:
              bpb Brian Burkhalter
              Reviewed By:
              Alan Bateman, Roger Riggs
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: