JDK-4039115 : ObjectInputStream constructor locks up application.
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io:serialization
  • Affected Version: 1.1
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5.1
  • CPU: sparc
  • Submitted: 1997-03-14
  • Updated: 1997-08-04
  • Resolved: 1997-08-04
Related Reports
Duplicate :  
Description

Name: sgC58550			Date: 03/14/97


In some cases, when you call the ObjectInputStream constructor
on a PipedInputStream, the Java application will freeze.  There
are no error messages; the system simply hangs.

 The problem specifically occurs when you are initializing a
thread with an externally visible ObjectInputStream (ie. A
serialization daemon that reads binhex-encoded bytes from an
external process and converts them back so the application
can use object serialization transparently).

  For example, the following code will compile correctly, but
the application will hang when the thread constructor is called:

class serializeDaemon extends Thread {

  public ObjectInputStream serializeStream;
  public PipedInputStream inPipe;

  private BufferedOutputStream processedData;
  
  public serializeDaemon(String name) {
    super(name);

    try {
      inPipe  = new PipedInputStream();

      //  Used by thread to pass on processed data.
      processedData  = new BufferedOutputStream(
                         new PipedOutputStream(inPipe));        

       //  Application hangs here.
	   serializeStream = new ObjectInputStream(inPipe);

     } catch (Exception e) {
	   System.out.println(e);
	 }
	
  }
  
  public void run() { etc...


company - Cornell University , email - ###@###.###
======================================================================

Comments
EVALUATION The ObjectOutputStream stream constructor writes the magic number and version to the stream but does not flush them out. premature flushing can cause a performance problem. This is a dup of 4026188 and 4030767
11-06-2004

WORK AROUND Name: sgC58550 Date: 03/14/97 You can achieve the same results for a little loss of transparency by constructing the ObjectInputStream after the thread is constucted. For example, remove all references to serializeStream in the above example and put the following in the main body of your application: serializeDaemon packetedObj = new serializeDaemon("myDaemon"); ObjectInputStream serializeStream = new ObjectInputStream(packetedObj.inPipe); The application now works fine, with some loss in code encapsulation. ======================================================================
11-06-2004

PUBLIC COMMENTS ObjectOutputStream writes a header to the stream that is expected by ObjectInputStream. The output stream should be flushed to prevent the input stream from blocking immediately.
10-06-2004