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

The java.io.PipedInputStream.read() method works wrong with closed stream

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1
    • Resolution: Fixed
    • Affects Version/s: 1.0.2
    • Fix Version/s: 1.1
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.1
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Not verified

      Description



      Name: saf@russia Date: 09/06/96


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

      The java.io.PipedInputStream.read() 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.3.1):

      "22.3.1 public abstract int read() throws
      IOException

      The general contract of read is that it reads one byte from the input
      stream. The byte is returned as an integer in the range 0 to 255
      (0x00-0xff). If no byte is available because the stream is at end of file,
      the value -1 is returned.

      This method blocks until input data is available, end of file is detected, or
      an exception is thrown.

      If the byte cannot be read for any reason other than end of file, an
      IOException is thrown. In particular, an IOException is thrown if the
      input stream has been closed (p. 22.3.6)."

      So this method should throw IOException
      if the input stream has been closed.
      But in fact it does not.
       
      Here is the minimized test demonstrating the bug:
          

      ----- test7.java ---------------------------------------
      import java.io.*;

      public class test7 {

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

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


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

        Attachments

          Activity

            People

            Assignee:
            djbrown David Brown (Inactive)
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: