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

IndexColorModel.getRGB() throws ArrayIndexOutOfBoundsException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 6
    • client-libs
    • None
    • 2d
    • b53
    • sparc
    • solaris_7

      According to the spec, ColorModel.getRGB() could only throw
      IllegalArgumentException "if pixel values for this ColorModel are not
      conveniently representable as a single int". However, the following program
      shows that ArrayIndexOutOfBoundsException is thrown from
      IndexColorModel.getRGB():

      import java.awt.*;
      import java.awt.image.*;

      public class IndexColorModelTest {
          public static void main(String[] args) {
              ColorModel cm = Toolkit.getDefaultToolkit().getColorModel();
              if (cm instanceof IndexColorModel) {
                  int[] pixels = { 0, 1, -1, Integer.MAX_VALUE, Integer.MIN_VALUE,
                                   50, 2467, 72693, -28, -892, -29023};
                  for (int i = 0; i < pixels.length; i++) {
                      try {
                          cm.getRGB(pixels[i]);
                      } catch (ArrayIndexOutOfBoundsException e) {
                          System.out.println("ArrayIndexOutOfBoundsException thrown on " + pixels[i]);
                      }
                  }
              }
          }
      }

      output:

      ArrayIndexOutOfBoundsException thrown on -1
      ArrayIndexOutOfBoundsException thrown on 2147483647
      ArrayIndexOutOfBoundsException thrown on -2147483648
      ArrayIndexOutOfBoundsException thrown on 2467
      ArrayIndexOutOfBoundsException thrown on 72693
      ArrayIndexOutOfBoundsException thrown on -28
      ArrayIndexOutOfBoundsException thrown on -892
      ArrayIndexOutOfBoundsException thrown on -29023

            campbell Christopher Campbell (Inactive)
            xwangsunw Xiaozhong Wang (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: