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

ByteArrayOutputStream should not throw IOExceptions

    XMLWordPrintable

Details

    • b07

    Description

      A DESCRIPTION OF THE REQUEST :
       

          ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
          baos.write(123); // does NOT have a throws-exception clause
          try
          {
            baos.write("Hello world".getBytes()); // HAS a throws-exception clause
          }
          catch (IOException e)
          {
            // even though it never happens
          }

      JUSTIFICATION :
      It's contradictive.
      And it's easy to solve, without impact.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The ByteArrayOutputStream class should extend the OutputStream#write(byte[]) method and remove the exception clause:

          @Override
          public void write(byte b[]) // no more exception here.
          {
            try { super.write(b); } catch(IOException ioe) {}
          }
      ACTUAL -
      Right now, you just always have to make an empty catch-block whenever you use this write(byte[]) method.

          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          try
          {
            baos.write(byteArray);
          }
          catch (IOException ioe)
          {
            // never happens
          }

      ---------- BEGIN SOURCE ----------
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          try
          {
            baos.write(byteArray);
          }
          catch (IOException ioe)
          {
            // never happens
          }
      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              bpb Brian Burkhalter
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: