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

Raster creation methods need some specification clean up

XMLWordPrintable

    • 2d
    • b17

      As per Java spec
      ArrayIndexOutOfBoundsException - if bankIndices or bandOffsets is null.

      If we provide bandOffsets as null, existing JDK implementation is throwing NullPointerException which is not as per spec. It should throw ArrayIndexOutOfBoundsException.

      A sample demonstrating the problem:
       public static void main(String[] args) {
              try {
                  WritableRaster writableRaster = Raster.createBandedRaster(
                          DataBuffer.TYPE_INT, 5, 1, 3, new int[]{0, 0}, null, new Point());
              } catch (Throwable t) {
                  System.out.println(t);
              }
          }

      Output:
      java.lang.NullPointerException: Cannot read the array length because "bandOffsets" is null.

      Code snippet causing issue:
             
              int bands = bandOffsets.length;

              if (bankIndices == null) {
                  throw new
                      ArrayIndexOutOfBoundsException("Bank indices array is null");
              }
              if (bandOffsets == null) {
                  throw new
                      ArrayIndexOutOfBoundsException("Band offsets array is null");
              }

            prr Philip Race
            amadgundi Asha Madgundi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: