United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4241014 : JComponent rectangleIsObscured causes ArrayOutOfBoundsException

Details
Type:
Bug
Submit Date:
1999-05-25
Status:
Closed
Updated Date:
1999-07-09
Project Name:
JDK
Resolved Date:
1999-07-09
Component:
client-libs
OS:
windows_nt
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Won't Fix
Affected Versions:
1.2.1
Fixed Versions:

Related Reports

Sub Tasks

Description

Name: vi73552			Date: 05/25/99


I'm writing Swing-based user interface where componenents are
added and removed from the interface frequently. 

On an occasional basis, especially when removing or adding a lot of components in a short time,
I get the following exception:

Exception occurred during event dispatching:
java.lang.ArrayIndexOutOfBoundsException: No such child: 7
        at java.awt.Container.getComponent(Container.java:148)
        at javax.swing.JComponent.rectangleIsObscured(JComponent.java:2816)
        at javax.swing.JComponent.paint(JComponent.java:546)
        at javax.swing.JLayeredPane.paint(JLayeredPane.java:547)
        at javax.swing.JComponent.paintWithBuffer(JComponent.java:3510)
        at javax.swing.JComponent._paintImmediately(JComponent.java:3472)
        at javax.swing.JComponent.paintImmediately(JComponent.java:3356)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:366)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.
java:185)
        at javax.swing.SystemEventQueueUtilities.processRunnableEvent(SystemEventQueueUtilities.java
:354)
        at javax.swing.SystemEventQueueUtilities.access$0(SystemEventQueueUtilities.java:350)
        at javax.swing.SystemEventQueueUtilities$RunnableTarget.processEvent(SystemEventQueueUtiliti
es.java:391)
        at java.awt.Component.dispatchEventImpl(Component.java:2376)
        at java.awt.Component.dispatchEvent(Component.java:2289)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:258)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:68)

A quick look at the  JComponent code reveals that the rectangleIsObscured method
has been changed between JDK version 1.1.7 to 1.2.

In version 1.2 it reads:
        int numChildren = getComponentCount();

        for(int i = 0; i < numChildren; i++) {
            Component child = getComponent(i);
            Rectangle childBounds;

IMHO this is the culprid. As this is not part of a synchronized block,
the component count may change between the call to getComponentCount()
and the call to getComponent.

The 1.1.7 approach seems much more reliable to me: It first
copies all components into an array and then loops on that array.
(Review ID: 83447) 
======================================================================

                                    

Comments
WORK AROUND



Name: vi73552			Date: 05/25/99


None.
In fact I tried to re-compile a 'fixed' version of JComponent,
but I could not find a way to make JRE prefer that one over the
default one.
======================================================================
                                     
2004-06-11
EVALUATION

Swing is not threadsafe, this is not a bug.
scott.violet@eng 1999-07-09
                                     
1999-07-09
PUBLIC COMMENTS

Swing is not threadsafe, this is not a bug.
scott.violet@eng 1999-07-09
                                     
1999-07-09



Hardware and Software, Engineered to Work Together