Troubleshooting java stack trace

I have a stack trace where I need a help interpretation:

java.lang.ArrayIndexOutOfBoundsException: 36 >= 36
    at java.util.Vector.elementAt(Vector.java:427)
    at javax.swing.tree.VariableHeightLayoutCache.getNode(VariableHeightLayoutCache.java:976)
    at javax.swing.tree.VariableHeightLayoutCache.getPreferredHeight(VariableHeightLayoutCache.java:274)
    at javax.swing.plaf.basic.BasicTreeUI.updateCachedPreferredSize(BasicTreeUI.java:1823)
    at javax.swing.plaf.basic.BasicTreeUI.getPreferredSize(BasicTreeUI.java:1924)
    at javax.swing.plaf.basic.BasicTreeUI.getPreferredSize(BasicTreeUI.java:1912)
    at javax.swing.JComponent.getPreferredSize(JComponent.java:1642)
    at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:769)
    at java.awt.Container.layout(Container.java:1420)
    at java.awt.Container.doLayout(Container.java:1409)
    at java.awt.Container.validateTree(Container.java:1506)
    at java.awt.Container.validate(Container.java:1479)
    at javax.swing.RepaintManager$2.run(RepaintManager.java:698)
    at javax.swing.RepaintManager$2.run(RepaintManager.java:696)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
    at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:695)
    at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1679)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:715)
    at java.awt.EventQueue.access$400(EventQueue.java:82)
    at java.awt.EventQueue$2.run(EventQueue.java:676)
    at java.awt.EventQueue$2.run(EventQueue.java:674)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:86)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:685)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

      

None of the files or functions on the stack are intended for my program, so according to my calculations it should be 100% internal to swing. This does not mean that this is not a fault of my program.

I can pretty much grasp the gist of what the JVM is doing at the time - it looks like it is reshaping one of my JTree components that is in the scrollbar (I have several so I don't know what that might be).

My best guess as to what might cause this error is that the contents of the tree (and therefore the number of nodes in it) changes at some point during repainting, so the vector that retains the child nodes changes in size it is processed to obtain the dimensions of the components.

Is this plausible?

If so, how can I get around it? I guess I would like to block the repainting when any update occurs, or alternatively, block the update while the repainting is taking place?

+3


source to share


1 answer


The normal way to "continue swing blocks while updating" is to limit any changes to the UI to the event dispatch flow; if you don't know (or the author of the program doesn't know / doesn't know) what this is, this indicates that that's part of the problem.

The error message (which I didn't find anything funny about, by the way) says that there is a vector (general collections did not come when Swing was written) with 36 elements in it, with indices 0-35; the code tried to access index 36 of this vector and thus the exception.



I would look for parts of the UI that change under any conditions, this is happening - is it changing data, resizing the window, what? The fact that the vector contains 36 elements should give you a few clues - do you have a place with many buttons of any type or something else? I suppose it could be a 36-component window; does the UI have a place where the component disappears from the window?

In the same area, I would be looking for some code that calls something like paint or repaint that is outside of the event dispatching thread - all such code should be executed on that thread. Have a look at SwingUtilities.invokeAndWait () for a way to do this without a big whitespace with existing code if it needs it.

+1


source







All Articles