Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4156970
Votes 0
Synopsis java.io.RandomAccessFile.readInt() does not throw EOFException
Category java:classes_io
Reported Against 1.2fcs
Release Fixed
State 11-Closed, duplicate of 4137835, bug
Priority: 2-High
Related Bugs 4137835
Submit Date 14-JUL-1998
Description





   The java.io.RandomAccessFile.readInt() does not throw EOFException and hangs
 if this file reaches the end before reading four bytes.
 
 The documentation says:
"
public final native int readInt() throws IOException

 Reads a signed 32-bit integer from this file. This method reads 4 
 bytes from the file, starting at the current file pointer. 
  ....
 This method blocks until the four bytes are read, the end of the 
 stream is detected, or an exception is thrown. 

 @return     the next four bytes of this file, interpreted as an
             int.
 @exception  EOFException  if this file reaches the end before reading
             ^^^^^^^^^^^^^^^^^^^
               four bytes.
 @exception  IOException   if an I/O error occurs.
" 
 
 
The example:
------------------------------8-<--------------------------------------------
import java.io.*;

class Test {
  public static void main(String[] argv) {
  
  try {
   FileOutputStream fos = new FileOutputStream("File.dat");
   fos.write(1);
   fos.close();
   
   RandomAccessFile raf = new RandomAccessFile("File.dat","rw");

   try {
    System.out.println("Read int ...");    
    int i=raf.readInt();
    System.out.println("No EOFException");
    System.exit(1);    
   } catch (IOException ex) {
    System.out.println("OKAY");
    System.exit(0);  
   }
   
   
  } catch (Exception e) {
    System.out.println("Unexpected:"+e);
    System.exit(0);   
  }
    
   }
}
---------------------------->-8----------------------------------------------
Output:
Read int ...
^C
java full version "JDK-1.2fcs-B"
	
======================================================================
Work Around




======================================================================
Evaluation
Bug introduced by fix to 4137835. Already integrated in last putback,
closing as a duplicate.
  xxxxx@xxxxx   1998-07-16
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang