-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
None
-
beta
-
generic
-
generic
In /src/share/classes/sun/awt/RepaintArea.java, we are potentially
leaking a Graphics. In the code below, the test for isEmpty()
should be done inside the try-finally block in order to make sure the
graphics obtained by use of comp.getGraphics() is properly disposed.
public void paint(Object target, boolean isClearRectOnPaint) {
Component comp = (Component)target;
Graphics g = comp.getGraphics();
if (g == null || isEmpty()) {
return;
}
try {
RepaintArea ra = this.cloneAndReset();
int numRects = ra.rectangleList.size();
union[HORIZONTAL] = union[VERTICAL] = null;
for (int nRect = 0; nRect < numRects; nRect++) {
Rectangle r = (Rectangle) ra.rectangleList.removeFirst();
int addTo = (r.width > r.height) ? HORIZONTAL : VERTICAL;
if (union[addTo] == null) {
union[addTo] = r;
} else {
union[addTo].add(r);
}
}
if(union[HORIZONTAL] != null && union[VERTICAL] != null) {
int square = ra.width * ra.height;
int benefit = square - union[HORIZONTAL].width*union[HORIZONTAL].height
- union[VERTICAL].width*union[VERTICAL].height;
// if benefit is comparable with bounding box
if (MAX_BENEFIT_RATIO * benefit > square) {
paintRect(comp, g, union[HORIZONTAL], isClearRectOnPaint);
paintRect(comp, g, union[VERTICAL], isClearRectOnPaint);
return;
}
}
paintRect(comp, g, ra, isClearRectOnPaint);
} finally {
g.dispose();
}
}
leaking a Graphics. In the code below, the test for isEmpty()
should be done inside the try-finally block in order to make sure the
graphics obtained by use of comp.getGraphics() is properly disposed.
public void paint(Object target, boolean isClearRectOnPaint) {
Component comp = (Component)target;
Graphics g = comp.getGraphics();
if (g == null || isEmpty()) {
return;
}
try {
RepaintArea ra = this.cloneAndReset();
int numRects = ra.rectangleList.size();
union[HORIZONTAL] = union[VERTICAL] = null;
for (int nRect = 0; nRect < numRects; nRect++) {
Rectangle r = (Rectangle) ra.rectangleList.removeFirst();
int addTo = (r.width > r.height) ? HORIZONTAL : VERTICAL;
if (union[addTo] == null) {
union[addTo] = r;
} else {
union[addTo].add(r);
}
}
if(union[HORIZONTAL] != null && union[VERTICAL] != null) {
int square = ra.width * ra.height;
int benefit = square - union[HORIZONTAL].width*union[HORIZONTAL].height
- union[VERTICAL].width*union[VERTICAL].height;
// if benefit is comparable with bounding box
if (MAX_BENEFIT_RATIO * benefit > square) {
paintRect(comp, g, union[HORIZONTAL], isClearRectOnPaint);
paintRect(comp, g, union[VERTICAL], isClearRectOnPaint);
return;
}
}
paintRect(comp, g, ra, isClearRectOnPaint);
} finally {
g.dispose();
}
}