-
Bug
-
Resolution: Fixed
-
P2
-
1.4.0
-
b86
-
x86, sparc
-
linux_redhat_7.2, solaris_2.6
Name: dsR10051 Date: 08/13/2001
Javadoc for class java.awt.Rectangle
should document that methods
public void add(int newx, int newy)
public void add(Point pt)
public void add(Rectangle r)
public Rectangle union(Rectangle r)
public void translate(int x, int y)
public void grow(int h, int v)
ignores the internal fields overflow and underflow during the calculations.
For example, the implementation of method translate(int x, int y) is:
public void translate(int x, int y) {
this.x += x;
this.y += y;
}
If this.x + x > Integer.MAX_VALUE, the additive operator is overflow and
new x coordinate is not equal to expected, mathematical correct result.
======================================================================
Look at following tests:
=== 1 ===
public class Test {
public static void main(String[] args) throws Exception {
Rectangle rec = new Rectangle(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
rec.add(-1, -1);
System.out.println("rec: " + rec);
}
}
rec: java.awt.Rectangle[x=-1,y=-1,width=-2147483648,height=-2147483648]
As a result we have a rectangle with negative width and height. It is unusual.
=== 2 ===
public class Test {
public static void main(String[] args) throws Exception {
Rectangle rec = new Rectangle(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
rec.union(new Rectangle(-1, -1, 1, 1));
System.out.println("rec: " + rec);
}
}
rec: java.awt.Rectangle[x=0,y=0,width=2147483647,height=2147483647]
As a result a rectangle doesn't have a point [-1, -1]. It is unusual.
=== 3 ===
public class Test {
public static void main(String[] args) throws Exception {
Rectangle rec = new Rectangle(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
rec.grow(1, 1);
System.out.println("rec: " + rec);
}
}
rec: java.awt.Rectangle[x=-1,y=-1,width=-2147483647,height=-2147483647]
As a result we have a rectangle with negative width and height. It is unusual.
=== 4 ===
public class Test {
public static void main(String[] args) throws Exception {
Rectangle rec = new Rectangle(Integer.MAX_VALUE, Integer.MAX_VALUE, 1, 1);
rec.translate(1, 1);
System.out.println("rec: " + rec);
}
}
rec: java.awt.Rectangle[x=-2147483648,y=-2147483648,width=1,height=1]
As a result we have a rectangle starting with [-2147483648,-2147483648] whereas previous start point was positive. It is unusual.
Javadoc for class java.awt.Rectangle
should document that methods
public void add(int newx, int newy)
public void add(Point pt)
public void add(Rectangle r)
public Rectangle union(Rectangle r)
public void translate(int x, int y)
public void grow(int h, int v)
ignores the internal fields overflow and underflow during the calculations.
For example, the implementation of method translate(int x, int y) is:
public void translate(int x, int y) {
this.x += x;
this.y += y;
}
If this.x + x > Integer.MAX_VALUE, the additive operator is overflow and
new x coordinate is not equal to expected, mathematical correct result.
======================================================================
Look at following tests:
=== 1 ===
public class Test {
public static void main(String[] args) throws Exception {
Rectangle rec = new Rectangle(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
rec.add(-1, -1);
System.out.println("rec: " + rec);
}
}
rec: java.awt.Rectangle[x=-1,y=-1,width=-2147483648,height=-2147483648]
As a result we have a rectangle with negative width and height. It is unusual.
=== 2 ===
public class Test {
public static void main(String[] args) throws Exception {
Rectangle rec = new Rectangle(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
rec.union(new Rectangle(-1, -1, 1, 1));
System.out.println("rec: " + rec);
}
}
rec: java.awt.Rectangle[x=0,y=0,width=2147483647,height=2147483647]
As a result a rectangle doesn't have a point [-1, -1]. It is unusual.
=== 3 ===
public class Test {
public static void main(String[] args) throws Exception {
Rectangle rec = new Rectangle(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
rec.grow(1, 1);
System.out.println("rec: " + rec);
}
}
rec: java.awt.Rectangle[x=-1,y=-1,width=-2147483647,height=-2147483647]
As a result we have a rectangle with negative width and height. It is unusual.
=== 4 ===
public class Test {
public static void main(String[] args) throws Exception {
Rectangle rec = new Rectangle(Integer.MAX_VALUE, Integer.MAX_VALUE, 1, 1);
rec.translate(1, 1);
System.out.println("rec: " + rec);
}
}
rec: java.awt.Rectangle[x=-2147483648,y=-2147483648,width=1,height=1]
As a result we have a rectangle starting with [-2147483648,-2147483648] whereas previous start point was positive. It is unusual.
- duplicates
-
JDK-4691305 Rectangle class does not describe how rectangles out of integer range are handle
-
- Closed
-
- relates to
-
JDK-6423143 Rectangle methods should protect against overflow conditions where possible
-
- Resolved
-