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

StringReader.skip(long ns) returns wrong value with negative param

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 5.0
    • 5.0
    • core-libs
    • tiger
    • sparc
    • solaris_2.6
    • Verified



      Name: auR10023 Date: 06/09/2003


      Filed By : SPB JCK team (###@###.###)
      JDK : java full version "1.5.0-beta-b07"
      Platform[s] : Solaris

      Specification excerpt:
      ======================
      --------- J2SE API spec v.1.5 ---------
      ...


      public long skip(long ns)
                throws IOException

      Skips the specified number of characters in the stream. Returns the number of characters that
      were skipped.

      The ns parameter may be negative, even though the the skip method of the Reader superclass
      throws an exception in this case. Using negative values for ns may later cause an
      IndexOutOfBoundsException to be thrown from other methods in this class. If the entire string
      has been read then negative skip values no longer have any effect.

      ...
      ---------- end-of-excerpt ---------------

      Problem description
      ===================
      Breefly the javadoc for the java.io.StringReader.skip(long) states:

          1. Method skip() should returns the number of characters actually skipped.
          2. Negative skip values no longe have any effect

      but following minimized test fails.
          
      Minimized test:
      ===============
      ------- t.java -------
      import java.io.*;

      public class t {
          public static void main (String [] args) throws IOException {
              StringReader reader = new StringReader("aaaa");
              long skNum = reader.skip(-10);
              if (skNum != 0) {
                  System.out.println("Method skip(-10) returns " +
                                     "unexpected value " + skNum);
              } else {
                  System.out.println("OKAY");
              }
          }
      }

      ------- end-of-t.java -------

      Minimized test output:
      ======================
      #java -version
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b07)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b07, mixed mode)


      #java t

      Method skip(-10) returns unexpected value -10


      Specific Machine Info:
      =====================
      SunOS archer 5.8 Generic_108528-20 sun4u sparc SUNW,Ultra-4

      Additional comments:
      ====================
      This jdk spec change was due CCC 4175312

      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            avusunw Avu Avu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: