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

some ImageOutputStreamImpl write methods throw unexpected exceptions

XMLWordPrintable

    • beta2
    • generic
    • generic
    • Not verified



      Name: vpR10011 Date: 04/17/2001



      Specification of the class javax.imageio.stream.ImageOutputStreamImpl says:

      "public void writeChars(char[] c, int off, int len) throws IOException
      ...
      Throws:
      IndexOutOfBoundsException - if off is negative, len is negative, or
           off + len is greater than c.length."

      But if len < 0 or off + len is greater than c.length then writeChars throws
      IllegalArgumentException.

      The following methods:
          writeDoubles(double[] d, int off, int len)
          writeFloats(float[] f, int off, int len)
          writeInts(int[] i, int off, int len)
          writeLongs(long[] l, int off, int len)
          writeShorts(short[] s, int off, int len)
      also throw IllegalArgumentException instead of IndexOutOfBoundsException
      if len < 0 or off + len is greater than array's length.

      To reproduce this bug run the following test:
      ---------------------test.java--------------
      import java.io.*;
      import javax.imageio.stream.*;

      public class test {

          public static void main(String[] argv) {
              OutputStream os = (OutputStream) new ByteArrayOutputStream();
              ImageOutputStreamImpl iosI = (ImageOutputStreamImpl) new MemoryCacheImageOutputStream(os);
              char [] c = {'a', 'b'};
      System.out.println("len < 0");
              try {
                  iosI.writeChars(c, 0, -2);
              } catch (IndexOutOfBoundsException e) {
                  System.out.println("Passed: " + e);
              } catch (Exception e) {
                  System.out.println("Failed: unexpected exception " + e);
              }
              System.out.println("off + len > c.length");
              try {
                  iosI.writeChars(c, 5, 100);
              } catch (IndexOutOfBoundsException e) {
                  System.out.println("Passed: " + e);
              } catch (Exception e) {
                  System.out.println("Failed: unexpected exception " + e);
              }
          }
      }
      --------------------------------------------
      % java -version
      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b60)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b60, mixed mode)
      % java test
      len < 0
      Failed: unexpected exception java.lang.IllegalArgumentException
      off + len > c.length
      Failed: unexpected exception java.lang.IllegalArgumentException


      This bug causes failure of the new JCK test
      api/javax_imageio/stream/ImageOutputStreamImpl/index.html#write


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

            dricesunw Daniel Rice (Inactive)
            verapsunw Verap Verap (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: