I have the following problem. I need to use some 3rd-party Swing-Components that I cannot change and have no influence on. However, in our situation one UI-component causes the following problem, after which it is no longer usable:
Uncaught exception in thread Thread[AWT-EventQueue-0,6,main]:
java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
at java.util.ArrayList.rangeCheck(ArrayList.java:653) ~[na:1.8.0_20]
at java.util.ArrayList.get(ArrayList.java:429) ~[na:1.8.0_20]
at java.awt.Container.createHierarchyEvents(Container.java:1439) ~[na:1.8.0_20]
at java.awt.Container.createHierarchyEvents(Container.java:1439) ~[na:1.8.0_20]
at java.awt.Container.createHierarchyEvents(Container.java:1439) ~[na:1.8.0_20]
at java.awt.Container.createHierarchyEvents(Container.java:1439) ~[na:1.8.0_20]
at java.awt.Component.hide(Component.java:1701) ~[na:1.8.0_20]
at java.awt.Window.hide(Window.java:1117) ~[na:1.8.0_20]
at javax.swing.Popup.hide(Popup.java:125) ~[na:1.8.0_20]
at javax.swing.PopupFactory$HeavyWeightPopup.hide(PopupFactory.java:474) ~[na:1.8.0_20]
at javax.swing.JPopupMenu.setVisible(JPopupMenu.java:796) ~[na:1.8.0_20]
at some.3rd.party.library.Component
Edit:
Funny enough, the component does only cause this exception if we add a HierarchyEventListener
to the Toolkit (via Toolkit.getDefaultToolkit().addAWTEventListener(ours, AWTEvent.HIERARCHY_EVENT_MASK);
) ... And it seems that this is a rare use case. Otherwise the code in java.awt.Container
that throws this exception does not get called at all!
Some Internet research indicates that the underlying cause is that the component is modified outside the EventQueue-Thread (from some code within the component!), but I think I can exclude the possibility.
Since I cannot access the code of the UI-component (and anyway have no idea where the problem gets caused), my proposed solution was to use java bootclasspath-option or javaagent technology to modify the java.awt.Container
class and essentially surround the createHierarchyEvents
with a try-catch-block. Honestly I don't care about the exception, as long as the component can still be used.
Edit2: Problem occurs on Win and Mac and the L&F doesn't seem to make a difference either. However, the problem is non-deterministic, meaning that it sometimes occurs at the second or third attempt.
Any ideas on that? Suggestions, how to proceed? Is this a good idea? Alternatives? Thanks for any input!