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

java.awt.image.SampleModel constructor unexpectedly throws IllegalArgumentException

XMLWordPrintable

    • 2d
    • b126
    • generic
    • generic
    • Verified

      Specification for constructor
      java.awt.image.SampleModel(int dataType, int w, int h, int numBands)
      says:

           * @throws IllegalArgumentException if the product of <code>w</code>
           * and <code>h</code> is greater than
           * <code>Integer.MAX_VALUE</code>

      This assertion is not satisfied.
      If width=1 and height=Integer.MAX_VALUE exception is thrown.
      Even if width=1 and height=Integer.MAX_VALUE-10 exception is still thrown.
      Please see the following code sample:
      -----
      import java.awt.image.DataBuffer;
      import java.awt.image.SampleModel;

      public class Temp {

          public static void main(String[] args) {

              final int w = Integer.MAX_VALUE - 10;
              final int h = 1;

              /**
               * @throws IllegalArgumentException if the product of <code>w</code>
               * and <code>h</code> is greater than
               * <code>Integer.MAX_VALUE</code>
               */
              new SampleModel(DataBuffer.TYPE_BYTE, w, h, 1) {

                  public int getNumDataElements() {
                      return 0;
                  }
                  public Object getDataElements(int x, int y, Object obj, DataBuffer data) {
                      return null;
                  }
                  public void setDataElements(int x, int y, Object obj, DataBuffer data) {

                  }
                  public int getSample(int x, int y, int b, DataBuffer data) {
                      return 0;
                  }
                  public void setSample(int x, int y, int b, int s, DataBuffer data) {

                  }
                  public SampleModel createCompatibleSampleModel(int w, int h) {
                      return null;
                  }
                  public SampleModel createSubsetSampleModel(int bands[]) {
                      return null;
                  }
                  public DataBuffer createDataBuffer() {
                      return null;
                  }
                  public int[] getSampleSize() {
                      return new int[0];
                  }
                  public int getSampleSize(int band) {
                      return 0;
                  }
              };
          }
      }

            bae Andrew Brygin
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: