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

FileImageInputStream.seek(long) does not make proper checkings

    XMLWordPrintable

    Details

      Description



      Name: mlR10151 Date: 04/12/2001



      The spec for the "public FileImageInputStream.seek(long pos)" reads:

      Throws:
                  IndexOutOfBoundsException - if pos is smaller the the flushed position.
                  EOFException - if the end of the stream is passed.
                  IOException - if any other I/O error occurs.

      But it
      1. Does not throw IOOBE when pos < flushed pos
      2. Throws IOE when pos < 0 (according to the spec, IOOBE must be thrown as far as flushed position is 0)
      3. Does not throw EOFExc. when end of the file is passed.

      To reproduce the bug run the following test:

      ========================== a.java =============================
      import java.io.*;
      import javax.imageio.stream.*;

      public class a {
          public static void main (String argv[]) throws Exception {
              RandomAccessFile raf = new RandomAccessFile("a.java", "r");
              FileImageInputStream fiis = new FileImageInputStream(raf);

              try {
                  System.out.println("pos < flushedPos...");
                  fiis.flushBefore(5);
                  fiis.seek(2);
                  System.out.println("Failed.");
              } catch (IndexOutOfBoundsException e) {
                  System.out.println("Passed.");
              }

              try {
                  System.out.println("pos < 0...");
                  fiis.seek(-2);
                  System.out.println("Failed.");
              } catch (IndexOutOfBoundsException e) {
                  System.out.println("Passed.");
              } catch (Exception e) {
                  System.out.println("Failed: " + e);
              }

              try {
                  System.out.println("pos > file length...");
                  fiis.seek(100000);
                  System.out.println("Failed.");
              } catch (EOFException e) {
                  System.out.println("Passed.");
              }

          }
      }
      ==========================log========================
      % java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b59)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b59, mixed mode)
      % java a
      pos < flushedPos...
      Failed.
      pos < 0...
      Failed: java.io.IOException: Negative seek offset
      pos > file length...
      Failed.


      This bug causes failure of the new JCK test
      api/javax_imageio/stream/FileImageInputStream/index.html#seek


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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dricesunw Daniel Rice (Inactive)
              Reporter:
              mlsunw Ml Ml (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: