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

java.io.RandomAccessFile.seek does not throw Exception

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P5 P5
    • None
    • 1.1.4
    • core-libs
    • None
    • x86
    • solaris_2.6



      Name: joT67522 Date: 10/20/97


      PROBLEM: The java lang spec, in section 22.23.5, clearly states for
      RandomAccessFile.seek that, "An IOException is thrown if pos is
      less than zero or greater than the length of the file". If we attempt
      to seek beyond the length of a file, however, it succeeds on both the
      Solaris and Windows versions of the JDK 1.1.4. This behaviour is
      contrary to the spec, and NOT platform independent behaviour.
      Note that this is NOT the same bug as 4017703, as that bug is
      entered for negative seeks.



      TO REPRODUCE: The following source code will reproduce the problem:



      ------ BEGIN SeekTest.java ------

      import java.io.*;



      public class SeekTest {

        public static void main(String[] args) {

          try {

            RandomAccessFile file;

            file = new RandomAccessFile("foo", "rw");

            System.out.println("file length == " +

                                file.length());

            file.seek(4096);

            file.close();

          } catch (IOException xcpt) {

            System.out.println(xcpt);

          }

        }

      }

      ------ END SeekTest.java ------



      RESULTS: operation succeeds, despite the fact that the seek was beyond the
      length of the file. IOException should have been thrown, but was not.



      CONFIGURATIONS: I tried this on several SparcStations running JDK 1.1.4, and
      on a WindowNT machine running JDK 1.1.4.
      ======================================================================

            mr Mark Reinhold
            johsunw Joon Oh (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: