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

java.io.PushbackInputStream.read works even when stream is closed

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2beta3
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Description



      Name: saC57035 Date: 12/02/96


      The java.io.PushbackInputStream.close() method isn't implemented.
      This fact causes compatibility bug against assertion that read() method
      should throw IOException if the stream is closed. (see Java Language
      Specification, 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."

      Here is the test demonstrating the bug:

      -----------------Test.java------------------------
      import java.io.*;

      public class Test {

      public static void main( String argv[] ) {
       byte[] data = {30,40};
       int b1,b2;
       PushbackInputStream in = new PushbackInputStream(new ByteArrayInputStream(data));
       try {
         in.unread(20);
         in.close();
       } catch (Throwable e) {
         System.out.println("Unexpected "+e+" is thrown");
       }
       try {
          in.read(); //IOException must be thrown here
         System.out.println("IOException not thrown");
       } catch (IOException e) {
         System.out.println("Test passed: IOException is thrown");
       } catch (Throwable e) {
         System.out.println("Unexpected "+e+" is thrown");
       }
        
      }

      }
      ---------Output from the test---------------------
      IOException not thrown
      --------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              mmcclosksunw Michael Mccloskey (Inactive)
              Reporter:
              savzan Stanislav Avzan (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: