JDK-4875941 : StringReader.skip(long ns) returns wrong value with negative param
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 2003-06-09
  • Updated: 2017-05-16
  • Resolved: 2003-08-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Description

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 

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

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b16 VERIFIED IN: tiger-b41
2004-06-14

EVALUATION Apparently the new spec must be more detailed, or else it must state that the behavior is not defined for negative skip values. ###@###.### 2003-06-09
2003-06-09