United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4875941 StringReader.skip(long ns) returns wrong value with negative param
JDK-4875941 : StringReader.skip(long ns) returns wrong value with negative param

Details
Type:
Bug
Submit Date:
2003-06-09
Status:
Closed
Updated Date:
2004-03-11
Project Name:
JDK
Resolved Date:
2003-08-15
Component:
core-libs
OS:
solaris_2.6
Sub-Component:
java.io
CPU:
sparc
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:
5.0 (tiger)

Related Reports

Sub Tasks

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
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
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



Hardware and Software, Engineered to Work Together