java.awt.image.SampleModel.setSamples() methods not always throw ArrayIndexOutOfBoundsException

XMLWordPrintable

    • 2d
    • b138
    • generic
    • generic
    • Verified

      The method
      public void setSamples(int x, int y, int w, int h, int b, int[] iArray, DataBuffer data)
      didn't throw ArrayIndexOutOfBoundsException in the following simple code:

      public class Sample {
          public static void main(String[] args) {
              int defaultWidth = 6;
              int defaultHeight = 4;
              SampleModel model =
                      Raster.createBandedRaster(DataBuffer.TYPE_INT, defaultWidth,
                              defaultHeight, 4, null).getSampleModel();
              DataBuffer data = model.createDataBuffer();
              int numElements = defaultWidth * defaultHeight * model.getNumBands();
              int[] a = new int[numElements];
              for (int j = 0; j < numElements; j++) {
                  a[j] = j;
              }
      model.setPixels(0, 0, defaultWidth, defaultHeight, a, data);
              float[] fArray = new float[defaultWidth * defaultHeight * model.getNumBands()];
              double[] dArray = new double[defaultWidth * defaultHeight * model.getNumBands()];
      model.setSamples(Integer.MAX_VALUE, 0, 1, 1, 0, fArray, data);
      System.out.println("setSamples works for x=2147483647, y=0, w=1 ,h=1");
          }
      }

      According to specification it should throw ArrayIndexOutOfBoundsException if the coordinates or the band index are not in bounds, or if iArray is too small to hold the input.

            Assignee:
            Andrew Brygin
            Reporter:
            Alexander Fomin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: