/* * Copyright (c) 2006, 2018, 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 6372340 * @summary Checks for infinite loop and OOM bugs dealing with Quad curves. * @run main/timeout=20/othervm QuadCurveOOMBug
*/
publicstaticvoid main(String[] args) { // Reversing the order of these try blocks has no effect. try {
testAdd();
} catch (IOException ioe) {
ioe.printStackTrace();
}
privatestaticvoid testSubtract() throws IOException
{
Shape lineShape = loadShape(strokedLineToSubtract, "Line");
Shape negShape = loadShape(negSpace, "Space");
Area lineArea = new Area(lineShape);
Area negArea = new Area(negShape);
System.err.println("Attempting to subtract ... ");
lineArea.subtract(negArea); // This is what throws the OutOfMemoryError
System.err.println("Subtraction succeeded.");
}
privatestaticvoid testAdd() throws IOException
{
Shape lineShape = loadShape(strokedLineToAdd, "Line");
Shape negShape = loadShape(shapeAdded, "Space");
Area lineArea = new Area(lineShape);
Area negArea = new Area(negShape);
System.err.println("Attempting to add ... ");
lineArea.add(negArea); // This is what throws the OutOfMemoryError
System.err.println("Addition succeeded.");
}
/** * Although this method isn't used by this test case, this is the method * used to create the two data sets that the test case uses. * @param name The name to give to the variable * @param shape
*/ publicstaticvoid saveShapeData(Shape shape, String name)
{
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
DataOutputStream os = new DataOutputStream(byteStream); try {
saveShapeToStream(shape, os);
System.out.println("\npublic static final byte[] " +
name + " = {\n"); byte[] data = byteStream.toByteArray(); int ii=0; for (byte bt : data)
System.out.print(" " + Byte.toString(bt) + "," +
((++ii)%20==0? "\n":""));
System.out.println("};");
} catch (IOException e) {
e.printStackTrace();
}
}
privatestaticvoid saveShapeToStream(Shape shape, DataOutputStream pOs) throws IOException
{
PathIterator iter = shape.getPathIterator(null); float[] coords = newfloat[6]; while(!iter.isDone()) { int type = iter.currentSegment(coords); switch(type) { case PathIterator.SEG_CLOSE:
pOs.writeUTF(SEG_CLOSE); break; case PathIterator.SEG_CUBICTO:
pOs.writeUTF(SEG_CUBICTO); for (float coord : coords)
pOs.writeFloat(coord); break; case PathIterator.SEG_LINETO:
pOs.writeUTF(SEG_LINETO);
pOs.writeFloat(coords[0]);
pOs.writeFloat(coords[1]); break; case PathIterator.SEG_MOVETO:
pOs.writeUTF(SEG_MOVETO);
pOs.writeFloat(coords[0]);
pOs.writeFloat(coords[1]); break; case PathIterator.SEG_QUADTO:
pOs.writeUTF(SEG_QUADTO); for (int ii=0; ii<4; ++ii)
pOs.writeFloat(coords[ii]); break; default:
System.err.print(" UNKNOWN:" + type); break;
}
iter.next();
}
}
publicstatic Shape loadShape(byte[] fileData, String name) throws IOException
{
System.out.println("\n\n" + name + ":");
GeneralPath path = new GeneralPath();
path.setWindingRule(GeneralPath.WIND_NON_ZERO);
DataInputStream is=null;
is = new DataInputStream(new ByteArrayInputStream(fileData)); float[] coords = newfloat[6]; while (is.available()>0)
{
String type = is.readUTF();
System.out.print("\n" + type + "\n "); if (type.equals(SEG_CLOSE)) {
path.closePath();
} elseif (type.equals(SEG_CUBICTO)) { for (int ii=0; ii<6; ++ii)
coords[ii] = readFloat(is);
path.curveTo(coords[0], coords[1],
coords[2], coords[3],
coords[4], coords[5]);
} elseif (type.equals(SEG_LINETO)) { for (int ii=0; ii<2; ++ii)
coords[ii] = readFloat(is);
path.lineTo(coords[0], coords[1]);
} elseif (type.equals(SEG_MOVETO)) { for (int ii=0; ii<2; ++ii)
coords[ii] = readFloat(is);
path.moveTo(coords[0], coords[1]);
} elseif (type.equals(SEG_QUADTO)) { for (int ii=0; ii<4; ++ii)
coords[ii] = readFloat(is);
path.quadTo(coords[0], coords[1], coords[2], coords[3]);
}
} return path;
}
/** * This call reads all the float values and prints them out. * @param is * @return * @throws IOException
*/ privatestaticfloat readFloat(DataInputStream is) throws IOException
{ float ft = is.readFloat();
System.out.print("" + ft + ", "); return ft;
}
}
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.