diff --git a/jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLMaskFill.java b/jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLMaskFill.java index b75d5a4bf13..ab053f111dc 100644 --- a/jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLMaskFill.java +++ b/jdk/src/java.desktop/share/classes/sun/java2d/opengl/OGLMaskFill.java @@ -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 @@ class OGLMaskFill extends BufferedMaskFill { 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); diff --git a/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DMaskFill.java b/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DMaskFill.java index e5e3d25a185..dae1d08a4d5 100644 --- a/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DMaskFill.java +++ b/jdk/src/java.desktop/windows/classes/sun/java2d/d3d/D3DMaskFill.java @@ -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 @@ class D3DMaskFill extends BufferedMaskFill { 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); diff --git a/jdk/test/sun/java2d/ClassCastExceptionForInvalidSurface.java b/jdk/test/sun/java2d/ClassCastExceptionForInvalidSurface.java index 6569e53450d..956815e6e35 100644 --- a/jdk/test/sun/java2d/ClassCastExceptionForInvalidSurface.java +++ b/jdk/test/sun/java2d/ClassCastExceptionForInvalidSurface.java @@ -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 @@ public final class ClassCastExceptionForInvalidSurface { 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();