6427331: NullPointerException in LookupOp.filter(Raster, WritableRaster)
authoraghaisas
Wed, 03 Aug 2016 14:49:01 +0530
changeset 40173 668a4cd8de97
parent 40172 87175987096e
child 40174 1c3f804fff32
child 40421 d5ee65e2b0fb
6427331: NullPointerException in LookupOp.filter(Raster, WritableRaster) Reviewed-by: psadhukhan, prr
jdk/src/java.desktop/share/classes/java/awt/image/LookupOp.java
jdk/test/java/awt/image/LookupOp/RasterOpNullDestinationRasterTest.java
--- a/jdk/src/java.desktop/share/classes/java/awt/image/LookupOp.java	Wed Aug 03 14:45:25 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/awt/image/LookupOp.java	Wed Aug 03 14:49:01 2016 +0530
@@ -1,6 +1,6 @@
 
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -253,7 +253,6 @@
      */
     public final WritableRaster filter (Raster src, WritableRaster dst) {
         int numBands  = src.getNumBands();
-        int dstLength = dst.getNumBands();
         int height    = src.getHeight();
         int width     = src.getWidth();
         int srcPix[]  = new int[numBands];
@@ -268,7 +267,7 @@
                 IllegalArgumentException ("Width or height of Rasters do not "+
                                           "match");
         }
-        dstLength = dst.getNumBands();
+        int dstLength = dst.getNumBands();
 
         if (numBands != dstLength) {
             throw new
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/image/LookupOp/RasterOpNullDestinationRasterTest.java	Wed Aug 03 14:49:01 2016 +0530
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6427331
+ * @summary Test to check there is no NullPointerException raised if
+ * null raster is provided as destination in case of RasterOp.filter()
+ * @run main RasterOpNullDestinationRasterTest
+ */
+
+import java.awt.Point;
+import java.awt.image.ByteLookupTable;
+import java.awt.image.DataBuffer;
+import java.awt.image.DataBufferByte;
+import java.awt.image.LookupOp;
+import java.awt.image.PixelInterleavedSampleModel;
+import java.awt.image.Raster;
+import java.awt.image.RasterOp;
+import java.awt.image.SampleModel;
+
+public class RasterOpNullDestinationRasterTest {
+
+    public static void main(String[] args) {
+
+        byte[][] data = new byte[1][10];
+        ByteLookupTable lut = new ByteLookupTable(0, data);
+        RasterOp op = new LookupOp(lut, null);
+
+        int[] bandOffsets = {0};
+        Point location = new Point(0, 0);
+        DataBuffer db = new DataBufferByte(10 * 10);
+        SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
+                                                         10, 10, 1, 10,
+                                                         bandOffsets);
+
+        Raster src = Raster.createRaster(sm, db, location);
+
+        op.filter(src, null); // this used to result in NullPointerException
+    }
+}