JDK-4180942 : java.io.FileInputStream.skip(negative) throws IOException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5
  • CPU: sparc
  • Submitted: 1998-10-13
  • Updated: 2017-05-16
  • Resolved: 2004-09-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 Availability Release.

To download the current JDK release, click here.
Other
5.0 tigerFixed
Related Reports
Relates :  
Relates :  
Description
Name: saC57035			Date: 10/13/98


The FileInputStream.skip(n) method throws IOException if n is negative.
This behavior:
a) violates the general contract of the skip method documented in 
   the InputStream javadoc comments (".. If n is negative, 
   no bytes are skipped.")
b) works inconsistently with all other InputStream subclasses. All those
   classes return 0 and do nothing if skip(negative) is called.

Here is the test example:
----------------------------------------------------
import java.io.*;

public class Test {
    public static void main(String [] args) {
         FileInputStream f=null;
        try {
          f = new FileInputStream("Test.java");
        } catch (FileNotFoundException e) {
            System.out.println("File not found: Test.java");
            System.exit(0);
        }
        try {
          if (f.skip(-10) == 0)
            System.out.println("OKAY");
          else
            System.out.println("FAILED");
           
        } catch (Throwable e) {
            System.out.println("FAILED: "+e+" thrown");
            e.printStackTrace();
        }
    }
}
----------------------------------------------------
Here is the test output:
----------------------------------------------------
95% java Test
FAILED: java.io.IOException thrown
java.io.IOException
	at Test.main(Test.java:13)
----------------------------------------------------
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger FIXED IN: tiger INTEGRATED IN: tiger tiger-b07 VERIFIED IN: 1.5
17-09-2004

EVALUATION Yes, this is a bug. Note that while it was reported against JDK 1.2fcs, the test fails in all releases of JDK 1.1 as well. (In fact, the error output in the description is from a 1.1 VM, not a 1.2 VM, otherwise the detail string would be "Invalid argument".) The fix is to add the obvious check to the FileInputStream.skip native method. -- mr@eng 1998/10/13 The spec can be changed to mention that subclasses of InputStream may implement their skip methods somewhat differently, and to completely describe the current behavior of FileInputStream.skip in Mantis. ###@###.### 2002-05-09 The spec has been changed to clearly state that FileInputStream does not obey the spec of its superclass. ###@###.### 2003-05-01
09-05-2002