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

java.io.FileInputStream.skip(negative) throws IOException

XMLWordPrintable

    • tiger
    • sparc
    • solaris_2.5
    • Verified

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

            mmcclosksunw Michael Mccloskey (Inactive)
            savzan Stanislav Avzan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: