Last week I was playing with my toy line drawing editor again, and I noticed a very strange bug in the Java 2D graphics support under MacOS X. I wrote a tool to draw ovals, and it worked great. Then I wrote a tool to draw circles; it was just a subclass of the oval tool that constrained the vertical and horizontal axes to be the same dimension. It worked great, too, but I noticed that all my ovals (and other shapes, for that matter) were nicely antialiased, and all of the circles were jaggy.

Java2D circle bug

At first I thought I’d done something wrong, but the circle tool doesn’t change any of the drawing code from the oval tool.

It turns out that if you draw a circle using Java2D under MacOS X (at least using Java 1.3.1 under Jaguar) it does not do antialiasing at all. If you choose the oval tool and start sweeping out the bounding box, you can see it suddenly switch to jaggy pixels as the dimensions become completely circular, and then back to antialiased mode as you keep going. In the picture, both shapes were drawn with the oval tool; the only difference is that the one on the left has a square bounding box.

It doesn’t happen with Java on other platforms, or with Cocoa. My theory: there’s an optimization path in the Carbon port of Java2D. When it notices that it’s drawing a true circle, that optimization path kicks in, and there’s a bug so that it loses the quality hints.