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);
}
}