JDK-1267038 : java.io.PipedOutputStream.write(b) method does not work with unconnected streams
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.0.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5
  • CPU: sparc
  • Submitted: 1996-09-09
  • Updated: 1998-03-09
  • Resolved: 1998-03-09
Related Reports
Duplicate :  
Relates :  
Description
Name: saf@russia			Date: 09/09/96


This bug was found by St.Petersburg Java SQE team (by Stanislav Avzan).

The java.io.PipedOutputStream.write(b) method does not work according to 
the Java language specification if stream is unconnected.

The Java Language specification 
(Version 1.0 - August 1, 1996)
says the following (please see item 22.17.4):

"22.17.4 public void write(int b) throws IOException 

If a thread was reading data bytes from the connected piped input stream,
but the thread is no longer alive, then an IOException is thrown. 

Implements the write method of OutputStream (p. 22.15.1)."

So this method should  not throw NullPointerException.
But in fact when stream is unconnected it does.
 
By the way, the behaviour expected in this case is not explicitly documented.

This bug also affects write(b,off,len) method.  
 
Here is the minimized test demonstrating the bug:
    

----- test12.java ---------------------------------------
import java.io.*;

public class test12 {

   public static void main( String[] argv ) {
     PipedOutputStream os = new PipedOutputStream();
     try {
       os.write(1);
       System.out.println("No exceptions thrown");
     } catch(Throwable e) {
       // only IOException is allowed
       System.out.println("Exception <"+e+"> thrown"); 
     } 
   }
}

----- The output of the test: -------------------------

$JAVA test12
Exception <java.lang.NullPointerException> thrown

-------------------------------------------------------

 

Comments
EVALUATION Another piped stream bug.
11-06-2004