JDK-4401675 : java.io.ObjectOutputStream writeUTF() on solaris throws UTFDataFormatException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io:serialization
  • Affected Version: 1.4.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_1
  • CPU: sparc
  • Submitted: 2001-01-04
  • Updated: 2001-01-05
  • Resolved: 2001-01-05
Related Reports
Duplicate :  
Description
java.io.ObjectOutputStream writeUTF() on solaris throws UTFDataFormatException

On windows working  
jdk1.4 b46

Test Program:
--------------------------------------------------------
 
import java.io.*;
 
  
public class WriteReadUTF {
      
    public static void main(String[] args) throws Exception {
  	   StringBuffer stringBuffer = new StringBuffer("a"); 
	   //generate a stringbuffer with 65535 length by appending to stringBuffer
	   for( int i = 0; i < 65534; i++) {
		   stringBuffer.append("a");
	   }
	   
	   String string65535 = stringBuffer.toString();
	   //delete if file exists
       File f = new File("utfTestFile");
        if (f.exists()) {
           f.delete();
       }
       try {
	      
	       FileOutputStream wstream = new FileOutputStream("utfTestFile");
	       FileInputStream rstream = new FileInputStream("utfTestFile");
	       ObjectOutputStream wfile = new ObjectOutputStream(wstream);
           wfile.writeUTF(string65535);////writing string of length 65535 
           wfile.close();  
	      
	       ObjectInputStream rfile = new ObjectInputStream(rstream);
	        
	       String rString65535 = rfile.readUTF();
	   
	       if ( !(rString65535.equals(string65535))) {
	            throw new Exception("data1 not correctly read in WriteReadUTF()");
	       }  
	          
	       rfile.close();
	       System.out.println ("WriteReadUTF pass");
	   
	   } catch (Exception e) {
  	       System.out.println ("Exception thrown  in WriteReadUTF Failed  " + e);        	 	                 	        	
      	   e.printStackTrace(); 
       }
 	
   }
}
   
 ---------------------------------result------------------------
javapro:/home/pande/merlin/bugs/io/WriteReadUTF 23 % java WriteReadUTF
Exception thrown  in WriteReadUTF Failed  java.io.UTFDataFormatException
java.io.UTFDataFormatException
        at java.io.ObjectOutputStream$BlockDataOutputStream.writeUTF(ObjectOutputStream.java:1827)
        at java.io.ObjectOutputStream$BlockDataOutputStream.writeUTF(ObjectOutputStream.java:1658)
        at java.io.ObjectOutputStream.writeUTF(ObjectOutputStream.java:787)
        at WriteReadUTF.main(WriteReadUTF.java:25)


Comments
WORK AROUND Use the -XX:-UseOnStackReplacement flag, e.g.: java -XX:-UseOnStackReplacement WriteReadUTF
11-06-2004

EVALUATION ObjectOutputStream throws a UTFDataFormatException because it believes the length of the string's UTF encoding to be 59884729059720. This bogus value is the result of the long subtraction/addition hotspot optimization error reported in 4400340. A temporary workaround is to disable on-stack replacement by passing the flag -XX:-UseOnStackReplacement. michael.warres@east 2001-01-04
04-01-2001