-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
beta
-
sparc
-
solaris_2.6
Name: acR10002 Date: 12/03/2000
The javadoc for class java.awt.Rectangle says:
-------------------------
A Rectangle whose width or height is negative is considered empty.
...
No point can be contained by or inside an empty Rectangle.
-------------------------
However, implementation can violate this rule under certain conditions.
Please consider the following test:
--------- Test.java ------------------
import java.awt.Rectangle;
public class Test {
public static void main(String args[]) {
Rectangle r = new Rectangle(-1,-1,-1,-1);
if (r.inside(Integer.MAX_VALUE,Integer.MAX_VALUE)) {
System.out.println("FAILURE: empty rectangle contains a point");
} else {
System.out.println("OKAY");
}
}
}
--------------------------------------
An output will be (same for all JDK versions):
--> java Test
FAILURE: empty rectangle contains a point
This happens because of overflow conditions are reached during calculations.
To prevent this, regardless of an algorithm used to determine whether the point
belongs to rectangle or not, inside() method should check first whether this
rectangle is empty.
======================================================================
- relates to
-
JDK-6423143 Rectangle methods should protect against overflow conditions where possible
- Resolved