changeset 11714:b5f1b7e7f975

8158495: CCE: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.opengl.OGLSurfaceData Reviewed-by: serb, prr
author avu
date Mon, 06 Jun 2016 16:23:37 +0300
parents 31a85b394a22
children bde3f8eae7f9
files src/share/classes/sun/java2d/opengl/OGLMaskFill.java src/windows/classes/sun/java2d/d3d/D3DMaskFill.java test/sun/java2d/ClassCastExceptionForInvalidSurface.java
diffstat 3 files changed, 24 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/java2d/opengl/OGLMaskFill.java	Mon May 30 13:42:11 2016 +0300
+++ b/src/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/src/windows/classes/sun/java2d/d3d/D3DMaskFill.java	Mon May 30 13:42:11 2016 +0300
+++ b/src/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/test/sun/java2d/ClassCastExceptionForInvalidSurface.java	Mon May 30 13:42:11 2016 +0300
+++ b/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();