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

ByteArrayOutputStream.write(byte[]) should not throw IOException

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.4.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_8

      Description

      Name: nt126004 Date: 12/02/2002


      FULL PRODUCT VERSION :
      java version "1.3.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
      Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)

      FULL OPERATING SYSTEM VERSION : Any


      A DESCRIPTION OF THE PROBLEM :
      ByteArrayOutputStream does not override write(byte[])
      method of OutputStream. write(byte[]) of
      OutputStream throws IOException

      As a result one always
      has to do something like this:

      ByteArrayOutputStream b;

      try {
         b.write(buffer);
      } catch (IOException e) {
         // never happens
      }

      Otherwise compiler will complain.


      Note that I can avoid this by doing

         b.write(buffer, 0, buffer.length);

      Since this method is implemented in ByteArrayOutputStream

      This is very annoying.




      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      add the following in you program:


      ByteArrayOutputStream bos = new ByteArrayOutputStream();


      bos.write(new byte[1]);

      This will not compile and you will have to
      wrap it into a try block which is not necessary since
      this method actually never throws IOException


      try {
           bos.write(new byte[1]);
      } catch (IOException e){
          // never happens
      }






      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected - method should not need a try block around it
      Actual - try block needed, otherwise this will not compile

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Compiler: IOException musr be caught or declared thrown.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      include java.io.*;

      // this will not compile
      public class Test {
         public static void main(String[] x) {
              new ByteArrayOutputStream.write(new byte[1]);
         }
      }


      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Always include unnecessaty try/catch block -
      very awkward
      (Review ID: 167129)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                iris Iris Clark
                Reporter:
                nthompsosunw Nathanael Thompson (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: