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

Unexpected IllegalArgumentException in SampleModel ctor.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 5.0-pool
    • 1.2.1, 5.0
    • client-libs
    • None
    • 2d
    • generic, sparc
    • generic, solaris_9



      Name: lm153972 Date: 09/27/2004


      The specification for
      public SampleModel(int dataType, int w, int h, int numBands) says:
      "java.lang.IllegalArgumentException - if the product of w and h is greater than Integer.MAX_VALUE"
      However this exception is thrown when w*h = Integer.MAX_VALUE or when
      w*h is less than Intger.MAX_VALUE but difference is very small. For example
      w*h = Integer.MAX_VALUE - 1.

      See next example:
      (SampleModel is abstract class so createCompatibleSampleModel from PackedColorModel
      is used. But the exception was thrown in SampleModel constructor)
      ------------------------------- Test.java ----------------------------------------
      mport java.awt.color.*;
      import java.awt.image.*;
      import java.awt.*;

      class MyPackedColorModel extends PackedColorModel {
           public MyPackedColorModel(ColorSpace space, int bits, int[] colorMaskArray,
                   int alphaMask, boolean isAlphaPremultiplied, int trans,
                   int transferType) {
               super(space, bits, colorMaskArray, alphaMask, isAlphaPremultiplied,
                       trans, transferType);
           }
           public MyPackedColorModel(ColorSpace space, int bits, int rmask, int gmask,
                   int bmask, int amask, boolean isAlphaPremultiplied, int trans,
                   int transferType) {
               super(space, bits, rmask, gmask, bmask, amask, isAlphaPremultiplied,
                   trans, transferType);
           }
           public int getAlpha(int pixel) {
               return 0;
           }
           public int getRed(int pixel) {
               return 0;
           }
           public int getGreen(int pixel) {
               return 0;
           }
           public int getBlue(int pixel) {
               return 0;
           }
      }

      public class Test {
           public static void main(String[] a) {
               ColorSpace colorSpace = ColorSpace.getInstance(ColorSpace.CS_sRGB);
               int[] colorMaskArray = { 0x00ff0000, 0x0000ff00, 0x000000ff};
               int bits = 32;
               int alphaMask = 0xff000000;
               MyPackedColorModel model = new MyPackedColorModel(colorSpace,bits,
                       colorMaskArray, alphaMask, false, 1, java.awt.image.DataBuffer.TYPE_USHORT);
               SampleModel sm = model.createCompatibleSampleModel(1,Integer.MAX_VALUE - 1);

           }

      }
      --------------------------------- Output -------------------------------------

      Exception in thread "main" java.lang.IllegalArgumentException: Dimensions (width=1 height=2147483646) are too large
               at java.awt.image.SampleModel.<init>(SampleModel.java:112)
               at java.awt.image.SinglePixelPackedSampleModel.<init>(SinglePixelPackedSampleModel.java:124)
               at java.awt.image.SinglePixelPackedSampleModel.<init>(SinglePixelPackedSampleModel.java:91)
               at java.awt.image.PackedColorModel.createCompatibleSampleModel(PackedColorModel.java:293)
               at Test.main(Test.java:40)



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

            aghaisas Ajit Ghaisas
            lmesnik Leonid Mesnik
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: