-
Enhancement
-
Resolution: Fixed
-
P4
-
1.1.7, 1.2.0
-
beta
-
generic
-
generic
ingrid.yao@Eng 1999-03-10
In JDK 1.1.7B, Polygon.getBounds() returns not an object copy but a
reference copy of its field. It can cause serious side-effects.
test program
=============
import java.awt.*;
public class PolyTest {
public PolyTest() {
int[] x = {0,10,10,0};
int[] y = {0,0,10,10};
Polygon p = new Polygon(x,y,4);
System.out.println(p.getBounds());
Rectangle r = p.getBounds();
r.translate(-5,-5);
System.out.println(p.getBounds());
}
public static void main(String[] args) {
new PolyTest();
}
}
Translate r, the bounds of polygon is also translated
because getBounds() returns only regerence copy.
- duplicates
-
JDK-4317211 Polygon returns a reference to its cached bounds field
-
- Closed
-