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

java.io.LineNumberReader.skip does not update lineNumber correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P4 P4
    • None
    • 1.1.6
    • core-libs
    • sparc
    • solaris_2.5.1



      Name: dbT83986 Date: 02/17/99


      java.io.LineNumberReader.skip() does not correctly update
      the number of lines read.

      A previous bug (4134311) mentionned this after a certain size, but in fact
      it fails for all sizes (I tried it on a textfile of 187 bytes
      and it returned a linecount of 260!).

      also, note that skip returns and uses a long while
      getLineNumber and setLineNumber return and use an int.
      A large file containing many empty lines could cause an error.


      here is a snippet demonstrating the error:


      package test_LineReader;

      import java.io.*;

      public class CountIt
      {
          public static void main (String[] argv)
          {
              LineNumberReader thisReader = null;
              // PushbackLineReader thisReader = null;

              File inputFile = null;
              String currentLine = null;
              int lineNumber = 0;

              try
              {
                  inputFile = new File (argv[0]);

                  thisReader = new LineNumberReader (new FileReader(inputFile ));
                  // thisReader = new PushbackLineReader (new FileReader(inputFile ));

                  System.out.println ("This file has " +
                                      inputFile.length() +
                                      " bytes."
                                      );

                  thisReader.skip (inputFile.length() -1);

                  System.out.println ("This file has " +
                                      thisReader.getLineNumber() +
                                      " lines."
                                      );
              }
              catch(Exception ex)
              {
                  System.out.println (ex.toString());
              }
          } // main

      }
      (Review ID: 53289)
      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            dblairsunw Dave Blair (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: