java.awt.GeneralPath behavioural difference with Sun JRE

James Graham jamestgraham at gmail.com
Thu Sep 25 10:02:11 PDT 2008


I found a difference in behaviour with the Sun JRE and the Open JDK JRE

( Please let me know if this is the incorrect forum for submitting bug
reports for the Open JDK).

i.e.:

java-1.6.0-openjdk-1.6.0.0
jdk1.6.0_10

Here is the relevant code:
import java.awt.BasicStroke;
import java.awt.Point;
import java.awt.Shape;
import java.awt.geom.GeneralPath;
import java.io.PrintStream;
import java.util.Arrays;
public class GenPathOpenJDK {
    public static void main(String[] args) {
        outputProperties( System.out );
        GeneralPath path = new GeneralPath();
        int width = 300;
        BasicStroke stroke = new BasicStroke( width, 0, 0 );
        Point points[] = { new Point( 2130, 40675 ), new Point( 2130, 45575
) };
        path.moveTo( points[ 0 ].x, points[ 0 ].y );
        for( int i = 1; i < points.length; i++ ) {
            path.lineTo( points[ i ].x, points[ i ].y );
            path.moveTo( points[ i ].x, points[ i ].y );
        }
        path.closePath();
        Shape strokedShape = stroke.createStrokedShape( path );
        System.out.println( "Path of width " + width + " and points : " +
Arrays.toString( points ) );
        System.out.println( strokedShape.getBounds() );
    }
}

Open JDK throws an IllegalPathStateException

java.class.path : .
java.class.version : 50.0
java.compiler : null
java.home : /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre
java.io.tmpdir : /tmp
java.version : 1.6.0
java.vendor : Sun Microsystems Inc.
java.vendor.url : http://java.sun.com/
os.name : Linux
os.arch : i386
os.version : 2.6.25-14.fc9.i686
Exception in thread "main" java.awt.geom.IllegalPathStateException: missing
initial moveto in path definition
    at java.awt.geom.Path2D$Float.needRoom(Path2D.java:280)
    at java.awt.geom.Path2D.closePath(Path2D.java:1769)
    at
sun.java2d.pisces.PiscesRenderingEngine$1.close(PiscesRenderingEngine.java:102)
    at sun.java2d.pisces.Stroker.emitClose(Stroker.java:755)
    at sun.java2d.pisces.Stroker.finish(Stroker.java:729)
    at sun.java2d.pisces.Stroker.close(Stroker.java:592)
    at
sun.java2d.pisces.PiscesRenderingEngine.pathTo(PiscesRenderingEngine.java:248)
    at
sun.java2d.pisces.PiscesRenderingEngine.strokeTo(PiscesRenderingEngine.java:231)
    at
sun.java2d.pisces.PiscesRenderingEngine.createStrokedShape(PiscesRenderingEngine.java:85)
    at java.awt.BasicStroke.createStrokedShape(BasicStroke.java:296)
    at GenPathOpenJDK.main(GenPathOpenJDK.java:48)

The Sun JRE doesn't thrown an exception:
java.class.path : .
java.class.version : 50.0
java.compiler : null
java.home : /opt/james/java/jdk1.6.0_10/jre
java.io.tmpdir : /tmp
java.version : 1.6.0_10-rc2
java.vendor : Sun Microsystems Inc.
java.vendor.url : http://java.sun.com/
os.name : Linux
os.arch : i386
os.version : 2.6.25-14.fc9.i686
Path of width 300 and points : [java.awt.Point[x=2130,y=40675],
java.awt.Point[x=2130,y=45575]]
java.awt.Rectangle[x=1980,y=40675,width=300,height=4900]

Note:

I noticed that if I don't close the path, it doesn't throw an exception and
creates an empty shape:
e.g:
Rectangle[x=0,y=0,width=0,height=0]
whereas the Sun JRE creates the expected shape whether or not the path is
closed (via GeneralPath.closePath()).
e.g:
Rectangle[x=1980,y=40675,width=300,height=4900]

I don't have access to the source at the moment, so I can't provide any
insight into why there's a discrepancy. This was found in a unit test while
evaluating the Open JDK shipped with the latest release of Fedora (Fedora
9).


-- 
James T. Graham
jamestgraham at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/jdk6-dev/attachments/20080925/7d42205d/attachment.html 


More information about the jdk6-dev mailing list