8158495: CCE: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.opengl.OGLSurfaceData
authoravu
Mon, 06 Jun 2016 16:23:37 +0300
changeset 39028 0b738aef65d0
parent 39027 60fc2577ef28
child 39029 e4c4b4fb2723
8158495: CCE: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.opengl.OGLSurfaceData Reviewed-by: serb, prr
jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLMaskFill.java
jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DMaskFill.java
jdk/test/sun/java2d/ClassCastExceptionForInvalidSurface.java
--- a/jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLMaskFill.java	Fri Jun 03 12:27:06 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLMaskFill.java	Mon Jun 06 16:23:37 2016 +0300
@@ -26,6 +26,7 @@
 package sun.java2d.opengl;
 
 import java.awt.Composite;
+import sun.java2d.InvalidPipeException;
 import sun.java2d.SunGraphics2D;
 import sun.java2d.loops.GraphicsPrimitive;
 import sun.java2d.loops.GraphicsPrimitiveMgr;
@@ -67,7 +68,14 @@
     protected void validateContext(SunGraphics2D sg2d,
                                    Composite comp, int ctxflags)
     {
-        OGLSurfaceData dstData = (OGLSurfaceData)sg2d.surfaceData;
+        OGLSurfaceData dstData;
+        try {
+            dstData = (OGLSurfaceData) sg2d.surfaceData;
+        } catch (ClassCastException e) {
+            throw new InvalidPipeException("wrong surface data type: " +
+                                           sg2d.surfaceData);
+        }
+
         OGLContext.validateContext(dstData, dstData,
                                    sg2d.getCompClip(), comp,
                                    null, sg2d.paint, sg2d, ctxflags);
--- a/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DMaskFill.java	Fri Jun 03 12:27:06 2016 +0530
+++ b/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DMaskFill.java	Mon Jun 06 16:23:37 2016 +0300
@@ -26,6 +26,7 @@
 package sun.java2d.d3d;
 
 import java.awt.Composite;
+import sun.java2d.InvalidPipeException;
 import sun.java2d.SunGraphics2D;
 import sun.java2d.loops.GraphicsPrimitive;
 import sun.java2d.loops.GraphicsPrimitiveMgr;
@@ -67,7 +68,13 @@
     protected void validateContext(SunGraphics2D sg2d,
                                    Composite comp, int ctxflags)
     {
-        D3DSurfaceData dstData = (D3DSurfaceData)sg2d.surfaceData;
+        D3DSurfaceData dstData;
+        try {
+            dstData = (D3DSurfaceData) sg2d.surfaceData;
+        } catch (ClassCastException e) {
+            throw new InvalidPipeException("wrong surface data type: " +
+                                           sg2d.surfaceData);
+        }
         D3DContext.validateContext(dstData, dstData,
                                    sg2d.getCompClip(), comp,
                                    null, sg2d.paint, sg2d, ctxflags);
--- a/jdk/test/sun/java2d/ClassCastExceptionForInvalidSurface.java	Fri Jun 03 12:27:06 2016 +0530
+++ b/jdk/test/sun/java2d/ClassCastExceptionForInvalidSurface.java	Mon Jun 06 16:23:37 2016 +0300
@@ -22,10 +22,12 @@
  */
 
 import java.awt.Font;
+import java.awt.Graphics2D;
 import java.awt.GraphicsConfiguration;
 import java.awt.GraphicsEnvironment;
 import java.awt.Image;
 import java.awt.Rectangle;
+import java.awt.RenderingHints;
 import java.awt.font.FontRenderContext;
 import java.awt.font.GlyphVector;
 import java.awt.image.BufferedImage;
@@ -99,6 +101,11 @@
                 vi.createGraphics().drawString("123", 1, 1);
                 vi.createGraphics().draw(new Rectangle(0, 0, 10, 10));
                 vi.createGraphics().fillOval(0, 0, 10, 10);
+                final Graphics2D graphics = vi.createGraphics();
+                graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+                                          RenderingHints.VALUE_ANTIALIAS_ON);
+                graphics.fillPolygon(new int[] {0, 10, 10, 0},
+                                     new int [] {0, 0, 10, 10}, 4);
             }
         });
         t1.start();