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.
======================================================================
- duplicates
-
JDK-4097291 (spec) java.io.RandomAccessFile.seek: Specify behavior when seeking past EOF
-
- Closed
-