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

java.io.PushbackInputStream.available() returns incorrect number

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2beta2
    • CPU:
      x86, sparc
    • OS:
      solaris_2.5, windows_nt
    • Verification:
      Verified

      Description



      Name: saC57035 Date: 12/03/96


      The java.io.PushbackInputStream.available() method returns incorrect
      number of bytes available.


      Here is the test demonstrating the bug:

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

      public class Test {

      public static void main( String argv[] ) {
       PushbackInputStream in = new PushbackInputStream(
                new ByteArrayInputStream(new byte[10]),5);
       try {
         System.out.println("Here must be 10: "+in.available());
         in.read();
         System.out.println("Here must be 9: "+in.available());
         in.unread(20);
         System.out.println("Here must be 10: "+in.available());
         in.unread(20);
         System.out.println("Here must be 11: "+in.available());
       } catch (Throwable e) {
         System.out.println("Test failed: unexpected "+e+" is thrown");
       }
      }

      }
      ---------Output from the test---------------------
      Here must be 10: 15
      Here must be 9: 14
      Here must be 10: 13
      Here must be 11: 12
      -------------------------------------------------

      The bug is easy to fix replacing the statement in

          public int available() throws IOException {
      return pos + super.available();
          }

      with

      return buf.length - pos + super.available();

      That's all. Thanks.


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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              dviswanasunw Deepa Viswanathan (Inactive)
              Reporter:
              savzan Stanislav Avzan (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: