Does this snippet of code hang your thread?

I stumbled upon a series of geometry manipulations that cause the Area.subtract routine to hang (and never return) - which is obviously inappropriate behavior. I was thinking of submitting it as a bug - through some searching, I found someone else who was experiencing the same sort of issue ( http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25400 ) reported in 2005 for JamVM - his algorithm didn’t hang my environment. Anyway, here is the code-snippet, tell me if your main thread hangs and if you care to check, your JRE (just because I am curious):

I’m not sure why it hangs, but I do know that it shouldn’t - at the very least it should be throwing an exception.


package UnitTest;

import java.awt.Polygon;
import java.awt.geom.*;

public class Main
{
	
	public static void main(String[] args)
	{

		AffineTransform lightTransform0 = new AffineTransform();
		lightTransform0.translate(192,463);
		lightTransform0.scale(1.0F, 1.0F);

		Ellipse2D ellipse = new Ellipse2D.Float(-192, -96, 384, 192);
		Area lightArea = new Area(ellipse);
		lightArea = lightArea.createTransformedArea(lightTransform0);

		///////////////////////
		Area obstructionArea = new Area();

		Polygon obstructionPolygon0 = new Polygon();

		obstructionPolygon0.addPoint(176, 384);
		obstructionPolygon0.addPoint(208, 384);
		obstructionPolygon0.addPoint(208, -406);
		obstructionPolygon0.addPoint(176, -406);

		Area obstruction0 = new Area(obstructionPolygon0);
		obstruction0.intersect(lightArea);
		obstruction0.subtract(obstructionArea);
		obstructionArea.add(obstruction0);

		/////////////////////////

		Polygon obstructionPolygon1 = new Polygon();
		obstructionPolygon1.addPoint(96, 479);
		obstructionPolygon1.addPoint(96, 449);

		obstructionPolygon1.addPoint(-864, 459);
		obstructionPolygon1.addPoint(-864, 489);

		Area obstruction1 = new Area(obstructionPolygon1);
		obstruction1.intersect(lightArea);
		obstruction1.subtract(obstructionArea);
		obstructionArea.add(obstruction1);


		//This line should cause a hang!
                //So will lightArea.intersect(obstructionArea);
		lightArea.subtract(obstructionArea);
		
    }
}

Hangs here too (7u25)

Thanks. I suspected it would. I’ll issue a bug report if I can’t find anything recent on it.

The Area subtract routine I find is quite unpredictable - sometimes it takes about half a second to perform the subtraction which is just insane - most of the time it performs very quickly but it seems to arbitrarily and unpredictably screw up like this - I know it will probably take a while before the bug is fixed and rolled out so… I can’t use this API. I’m pretty sure though there are faster alternatives out there. I’m looking at JTS now.

Also hangs on Java 6 (last update).

The hang is in a class for which I don’t have the source handy, in sun.awt.geom.AreaOp, inner class SubOp, method calculate(Vector,Vector)

Hangs, 7u25-b16.