Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1267258

java.io.PipedOutputStream.write(b) method works wrong with closed stream

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2beta4
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Not verified

      Description



      Name: saf@russia Date: 09/10/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.

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

      "22.15.1 public abstract void write(int b) throws
      IOException

      The general contract for write is that one byte is written to the output
      stream. The byte to be written is the eight low-order bits of the argument
      b. The 24 high-order bits of b are ignored.

      If the byte cannot be written for any reason, an IOException is thrown. In
      particular, an IOException may be thrown if the output stream has been
      closed (p. 22.15.5)."

      So this method should throw IOException
      if the output stream has been closed.
      But in fact it does not.
       
      This bug affects also write(b,off,len) method.

      Here is the minimized test demonstrating the bug:
          

      ----- test17.java ---------------------------------------
      import java.io.*;

      public class test17 {

         public static void main( String[] argv ) {
           PipedOutputStream os = new PipedOutputStream();
           PipedInputStream is = new PipedInputStream();
           try {
             os.connect(is);
             os.close();
           } catch(Throwable e) {
             System.out.println("Test failed: unexpected <"+e+"> thrown");
             System.exit(1);
           }
           try {
             os.write(10);
             System.out.println("Test failed: IOException expected");

           } catch(IOException e) {
             System.out.println("Test passed: IOException thrown");
           } catch(Throwable e) {
             System.out.println("Test failed: unexpected <"+e+"> thrown");
           }
         }
      }

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

      $JAVA test17
      Test failed: IOException expected

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


      Workaround:
      None
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dviswanasunw Deepa Viswanathan (Inactive)
              Reporter:
              duke J. Duke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: