8283794: CCE in XRTextRenderer.drawGlyphList and XRMaskFill.MaskFill

Reviewed-by: serb, aghaisas
This commit is contained in:
Alexey Ushakov 2022-04-21 09:56:39 +00:00
parent d6b5a63577
commit 90983431c5
12 changed files with 62 additions and 110 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, 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
@ -24,8 +24,8 @@
*/
package sun.java2d.metal;
import sun.java2d.InvalidPipeException;
import sun.java2d.SunGraphics2D;
import sun.java2d.SurfaceData;
import sun.java2d.loops.CompositeType;
import sun.java2d.loops.GraphicsPrimitive;
import sun.java2d.loops.GraphicsPrimitiveMgr;
@ -70,13 +70,8 @@ class MTLMaskFill extends BufferedMaskFill {
protected void validateContext(SunGraphics2D sg2d,
Composite comp, int ctxflags)
{
MTLSurfaceData dstData;
try {
dstData = (MTLSurfaceData) sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " +
sg2d.surfaceData);
}
MTLSurfaceData dstData = SurfaceData.convertTo(MTLSurfaceData.class,
sg2d.surfaceData);
MTLContext.validateContext(dstData, dstData,
sg2d.getCompClip(), comp,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, 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
@ -25,8 +25,8 @@
package sun.java2d.metal;
import sun.java2d.InvalidPipeException;
import sun.java2d.SunGraphics2D;
import sun.java2d.SurfaceData;
import sun.java2d.loops.GraphicsPrimitive;
import sun.java2d.pipe.BufferedRenderPipe;
import sun.java2d.pipe.ParallelogramPipe;
@ -49,12 +49,8 @@ class MTLRenderer extends BufferedRenderPipe {
int ctxflags =
sg2d.paint.getTransparency() == Transparency.OPAQUE ?
MTLContext.SRC_IS_OPAQUE : MTLContext.NO_CONTEXT_FLAGS;
MTLSurfaceData dstData;
try {
dstData = (MTLSurfaceData)sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
}
MTLSurfaceData dstData = SurfaceData.convertTo(MTLSurfaceData.class,
sg2d.surfaceData);
MTLContext.validateContext(dstData, dstData,
sg2d.getCompClip(), sg2d.composite,
null, sg2d.paint, sg2d, ctxflags);
@ -63,12 +59,8 @@ class MTLRenderer extends BufferedRenderPipe {
@Override
protected void validateContextAA(SunGraphics2D sg2d) {
int ctxflags = MTLContext.NO_CONTEXT_FLAGS;
MTLSurfaceData dstData;
try {
dstData = (MTLSurfaceData)sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
}
MTLSurfaceData dstData = SurfaceData.convertTo(MTLSurfaceData.class,
sg2d.surfaceData);
MTLContext.validateContext(dstData, dstData,
sg2d.getCompClip(), sg2d.composite,
null, sg2d.paint, sg2d, ctxflags);
@ -82,12 +74,8 @@ class MTLRenderer extends BufferedRenderPipe {
int ctxflags =
sg2d.surfaceData.getTransparency() == Transparency.OPAQUE ?
MTLContext.SRC_IS_OPAQUE : MTLContext.NO_CONTEXT_FLAGS;
MTLSurfaceData dstData;
try {
dstData = (MTLSurfaceData)sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
}
MTLSurfaceData dstData = SurfaceData.convertTo(MTLSurfaceData.class,
sg2d.surfaceData);
MTLContext.validateContext(dstData, dstData,
sg2d.getCompClip(), sg2d.composite,
null, null, null, ctxflags);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, 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
@ -1091,4 +1091,15 @@ public abstract class SurfaceData
public double getDefaultScaleY() {
return 1;
}
/**
* Converts surfaceData to the particular subclass or throws InvalidPipeException
*/
public static <T> T convertTo(Class<T> surfaceDataClass, SurfaceData surfaceData) {
try {
return surfaceDataClass.cast(surfaceData);
} catch(ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + surfaceData);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, 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
@ -26,8 +26,8 @@
package sun.java2d.opengl;
import java.awt.Composite;
import sun.java2d.InvalidPipeException;
import sun.java2d.SunGraphics2D;
import sun.java2d.SurfaceData;
import sun.java2d.loops.GraphicsPrimitive;
import sun.java2d.loops.GraphicsPrimitiveMgr;
import sun.java2d.loops.CompositeType;
@ -68,13 +68,8 @@ class OGLMaskFill extends BufferedMaskFill {
protected void validateContext(SunGraphics2D sg2d,
Composite comp, int ctxflags)
{
OGLSurfaceData dstData;
try {
dstData = (OGLSurfaceData) sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " +
sg2d.surfaceData);
}
OGLSurfaceData dstData = SurfaceData.convertTo(OGLSurfaceData.class,
sg2d.surfaceData);
OGLContext.validateContext(dstData, dstData,
sg2d.getCompClip(), comp,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, 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
@ -27,8 +27,8 @@ package sun.java2d.opengl;
import java.awt.Transparency;
import java.awt.geom.Path2D;
import sun.java2d.InvalidPipeException;
import sun.java2d.SunGraphics2D;
import sun.java2d.SurfaceData;
import sun.java2d.loops.GraphicsPrimitive;
import sun.java2d.pipe.BufferedRenderPipe;
import sun.java2d.pipe.ParallelogramPipe;
@ -47,12 +47,8 @@ class OGLRenderer extends BufferedRenderPipe {
int ctxflags =
sg2d.paint.getTransparency() == Transparency.OPAQUE ?
OGLContext.SRC_IS_OPAQUE : OGLContext.NO_CONTEXT_FLAGS;
OGLSurfaceData dstData;
try {
dstData = (OGLSurfaceData)sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
}
OGLSurfaceData dstData = SurfaceData.convertTo(OGLSurfaceData.class,
sg2d.surfaceData);
OGLContext.validateContext(dstData, dstData,
sg2d.getCompClip(), sg2d.composite,
null, sg2d.paint, sg2d, ctxflags);
@ -61,12 +57,8 @@ class OGLRenderer extends BufferedRenderPipe {
@Override
protected void validateContextAA(SunGraphics2D sg2d) {
int ctxflags = OGLContext.NO_CONTEXT_FLAGS;
OGLSurfaceData dstData;
try {
dstData = (OGLSurfaceData)sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
}
OGLSurfaceData dstData = SurfaceData.convertTo(OGLSurfaceData.class,
sg2d.surfaceData);
OGLContext.validateContext(dstData, dstData,
sg2d.getCompClip(), sg2d.composite,
null, sg2d.paint, sg2d, ctxflags);
@ -80,12 +72,8 @@ class OGLRenderer extends BufferedRenderPipe {
int ctxflags =
sg2d.surfaceData.getTransparency() == Transparency.OPAQUE ?
OGLContext.SRC_IS_OPAQUE : OGLContext.NO_CONTEXT_FLAGS;
OGLSurfaceData dstData;
try {
dstData = (OGLSurfaceData)sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
}
OGLSurfaceData dstData = SurfaceData.convertTo(OGLSurfaceData.class,
sg2d.surfaceData);
OGLContext.validateContext(dstData, dstData,
sg2d.getCompClip(), sg2d.composite,
null, null, null, ctxflags);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2022, 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
@ -27,6 +27,7 @@ package sun.font;
import sun.awt.*;
import sun.java2d.SunGraphics2D;
import sun.java2d.SurfaceData;
import sun.java2d.pipe.GlyphListPipe;
import sun.java2d.xr.*;
@ -61,8 +62,7 @@ public class XRTextRenderer extends GlyphListPipe {
try {
SunToolkit.awtLock();
XRSurfaceData x11sd = (XRSurfaceData) sg2d.surfaceData;
XRSurfaceData x11sd = SurfaceData.convertTo(XRSurfaceData.class, sg2d.surfaceData);
x11sd.validateAsDestination(null, sg2d.getCompClip());
x11sd.maskBuffer.validateCompositeState(sg2d.composite, sg2d.transform, sg2d.paint, sg2d);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2022, 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
@ -99,7 +99,7 @@ public class XRMaskFill extends MaskFill {
try {
SunToolkit.awtLock();
XRSurfaceData x11sd = (XRSurfaceData) sData;
XRSurfaceData x11sd = SurfaceData.convertTo(XRSurfaceData.class, sData);
x11sd.validateAsDestination(null, sg2d.getCompClip());
XRCompositeManager maskBuffer = x11sd.maskBuffer;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2022, 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
@ -28,8 +28,8 @@ package sun.java2d.xr;
import java.awt.*;
import java.awt.geom.*;
import sun.awt.SunToolkit;
import sun.java2d.InvalidPipeException;
import sun.java2d.SunGraphics2D;
import sun.java2d.SurfaceData;
import sun.java2d.loops.*;
import sun.java2d.pipe.Region;
import sun.java2d.pipe.PixelDrawPipe;
@ -70,12 +70,8 @@ public class XRRenderer implements PixelDrawPipe, PixelFillPipe, ShapeDrawPipe {
* destination context.
*/
private void validateSurface(SunGraphics2D sg2d) {
XRSurfaceData xrsd;
try {
xrsd = (XRSurfaceData) sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
}
XRSurfaceData xrsd = SurfaceData.convertTo(XRSurfaceData.class,
sg2d.surfaceData);
xrsd.validateAsDestination(sg2d, sg2d.getCompClip());
xrsd.maskBuffer.validateCompositeState(sg2d.composite, sg2d.transform,
sg2d.paint, sg2d);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2022, 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
@ -26,8 +26,8 @@
package sun.java2d.d3d;
import java.awt.Composite;
import sun.java2d.InvalidPipeException;
import sun.java2d.SunGraphics2D;
import sun.java2d.SurfaceData;
import sun.java2d.loops.GraphicsPrimitive;
import sun.java2d.loops.GraphicsPrimitiveMgr;
import sun.java2d.loops.CompositeType;
@ -68,13 +68,8 @@ class D3DMaskFill extends BufferedMaskFill {
protected void validateContext(SunGraphics2D sg2d,
Composite comp, int ctxflags)
{
D3DSurfaceData dstData;
try {
dstData = (D3DSurfaceData) sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " +
sg2d.surfaceData);
}
D3DSurfaceData dstData = SurfaceData.convertTo(D3DSurfaceData.class,
sg2d.surfaceData);
D3DContext.validateContext(dstData, dstData,
sg2d.getCompClip(), comp,
null, sg2d.paint, sg2d, ctxflags);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2022, 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
@ -27,8 +27,8 @@ package sun.java2d.d3d;
import java.awt.Transparency;
import java.awt.geom.Path2D;
import sun.java2d.InvalidPipeException;
import sun.java2d.SunGraphics2D;
import sun.java2d.SurfaceData;
import sun.java2d.loops.GraphicsPrimitive;
import sun.java2d.pipe.BufferedRenderPipe;
import sun.java2d.pipe.RenderQueue;
@ -47,12 +47,8 @@ class D3DRenderer extends BufferedRenderPipe {
int ctxflags =
sg2d.paint.getTransparency() == Transparency.OPAQUE ?
D3DContext.SRC_IS_OPAQUE : D3DContext.NO_CONTEXT_FLAGS;
D3DSurfaceData dstData;
try {
dstData = (D3DSurfaceData)sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
}
D3DSurfaceData dstData = SurfaceData.convertTo(D3DSurfaceData.class,
sg2d.surfaceData);
D3DContext.validateContext(dstData, dstData,
sg2d.getCompClip(), sg2d.composite,
null, sg2d.paint, sg2d, ctxflags);
@ -61,12 +57,8 @@ class D3DRenderer extends BufferedRenderPipe {
@Override
protected void validateContextAA(SunGraphics2D sg2d) {
int ctxflags = D3DContext.NO_CONTEXT_FLAGS;
D3DSurfaceData dstData;
try {
dstData = (D3DSurfaceData)sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
}
D3DSurfaceData dstData = SurfaceData.convertTo(D3DSurfaceData.class,
sg2d.surfaceData);
D3DContext.validateContext(dstData, dstData,
sg2d.getCompClip(), sg2d.composite,
null, sg2d.paint, sg2d, ctxflags);
@ -80,12 +72,8 @@ class D3DRenderer extends BufferedRenderPipe {
int ctxflags =
sg2d.surfaceData.getTransparency() == Transparency.OPAQUE ?
D3DContext.SRC_IS_OPAQUE : D3DContext.NO_CONTEXT_FLAGS;
D3DSurfaceData dstData;
try {
dstData = (D3DSurfaceData)sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
}
D3DSurfaceData dstData = SurfaceData.convertTo(D3DSurfaceData.class,
sg2d.surfaceData);
D3DContext.validateContext(dstData, dstData,
sg2d.getCompClip(), sg2d.composite,
null, null, null, ctxflags);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2022, 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
@ -292,12 +292,8 @@ public class GDIRenderer implements
// method that could be filled by the doShape method more quickly.
public void doFillSpans(SunGraphics2D sg2d, SpanIterator si) {
int[] box = new int[4];
GDIWindowSurfaceData sd;
try {
sd = (GDIWindowSurfaceData)sg2d.surfaceData;
} catch (ClassCastException e) {
throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
}
GDIWindowSurfaceData sd = SurfaceData.convertTo(GDIWindowSurfaceData.class,
sg2d.surfaceData);
Region clip = sg2d.getCompClip();
Composite comp = sg2d.composite;
int eargb = sg2d.eargb;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2022 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
@ -41,7 +41,7 @@ import static java.awt.image.BufferedImage.TYPE_INT_ARGB;
/**
* @test
* @key headful
* @bug 8158072 7172749
* @bug 8158072 7172749 8283794
*/
public final class ClassCastExceptionForInvalidSurface {