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

java.awt.image.SampleModel.getPixels() methods not allways throw ArrayIndexOutOfBoundsException

    Details

    • Subcomponent:
      2d
    • Resolved In Build:
      b138
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Backports

        Description

        Methods

         public double[] getPixels(int x, int y, int w, int h, double dArray[], DataBuffer data)
         public float[] getPixels(int x, int y, int w, int h, float fArray[], DataBuffer data)

        declare:

          /**
           * @throws ArrayIndexOutOfBoundsException if the coordinates are
           * not in bounds, or if dArray is too small to hold the output.
           */
        This statement is not always satisfied. Please see the following code sample that illustrates not throwing ArrayIndexOutOfBoundsException from getPixels() methods.
        -----

        import java.awt.image.*;

        public class Sample {

            public static void main(String[] args) {

                int defaultWidth = 10;
                int defaultHeight = 10;
                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()];
                /**
                 * @throws ArrayIndexOutOfBoundsException if the coordinates are
                 * not in bounds, or if fArray is too small to hold the output.
                 */
                model.getPixels(Integer.MAX_VALUE, 0, 1, 1, fArray, data);
                model.getPixels(0, Integer.MAX_VALUE, 1, 1, fArray, data);

                double[] dArray = new double[defaultWidth * defaultHeight * model.getNumBands()];
                /**
                 * @throws ArrayIndexOutOfBoundsException if the coordinates are
                 * not in bounds, or if dArray is too small to hold the output.
                 */
                model.getPixels(Integer.MAX_VALUE, 0, 1, 1, dArray, data);
                model.getPixels(0, Integer.MAX_VALUE, 1, 1, dArray, data);
            }
        }
        -----

        This problem leads to failing JCK tests:

        api/java_awt/Image/SampleModel/index.html#GetsetPixels[getsetPixels0009]
        api/java_awt/Image/SampleModel/index.html#GetsetPixels[getsetPixels0008]

        JDK 6,7
        Platforms: Solaris, Windows

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: