JDK-4156970 : java.io.RandomAccessFile.readInt() does not throw EOFException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.2.0
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5.1
  • CPU: sparc
  • Submitted: 1998-07-14
  • Updated: 1998-07-16
  • Resolved: 1998-07-16
Related Reports
Duplicate :  
Description

Name: akC57697			Date: 07/14/98



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

Comments
WORK AROUND Name: akC57697 Date: 07/14/98 ======================================================================
20-08-2004

EVALUATION Bug introduced by fix to 4137835. Already integrated in last putback, closing as a duplicate. benedict.gomes@eng 1998-07-16
16-07-1998