I have setup a Matlab-function which uses the undocumented Matlab function "uitree". "uitree" exists yet since more than 10 years and is still (R2016b) "offered" by MATLAB to be used. I used the return value (handle) of "uitree" with some simple "java" functions for adding and removing tree-nodes during execution of my m-function.
But when processing one very big file (which I use for regression testing of my m-function) with my m-function I get the following (error) message, which is displayed in red color in the Matlab command window. This message does only appear sporadically, let's say when I process the same big file 10 times it occurs 1 time. And the message is exactly the same, also the numbers are 245 and 241.
This message does not cause any error within MATLAB and I didn't see any anomaly in the results of processing the big file, but I would like to understand what is the cause and what I can do to avoid it. Unfortunately due to reasons above (sporadic and doesn't cause any error) I had no luck when trying to add breakpoints and display messages to find the location. And unfortunately also that I am not at all familiar with Java, Swing and Awt :-(.
In difference to the similar question already raised "What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it?" in my case it is occuring sporadic, so the message comes occasionally with one and the same file being processed.
Can anybody give me some hint, what it could be and what I can do else to find the cause of the problem?
Java Message displayed in MATLAB command window
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 245 >= 241
at java.util.Vector.removeElementAt(Unknown Source)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.collapse(Unknown Source)
at javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.collapse(Unknown Source)
at javax.swing.tree.VariableHeightLayoutCache.setExpandedState(Unknown Source)
at javax.swing.plaf.basic.BasicTreeUI$Handler.treeCollapsed(Unknown Source)
at javax.swing.JTree.fireTreeCollapsed(Unknown Source)
at javax.swing.JTree.setExpandedState(Unknown Source)
at javax.swing.JTree.collapsePath(Unknown Source)
at com.mathworks.hg.peer.UITreePeer$4.run(UITreePeer.java:221)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Here an overview of related m-functions and Java-functions that are used:
Undocumented MATLAB functions used:
hTree = uitree
jTree = hTree.Tree
hTreeNode = uitreenode
hTree
being of class: javahandle_withcallbacks.com.mathworks.hg.peer.UITreePeer
jTree
being of class: javahandle_withcallbacks.com.mathworks.hg.peer.utils.UIMJTree
hTreeNode
being of class: javahandle.com.mathworks.hg.peer.UITreeNode
Java/MATLAB functions used:
I don't know exactly what comes directly from Java and what is something in the interface between Java/MATLAB and implemented by MATLAB ... code snippets
% For Tree Context Menu
hJTree= handle(jTree, 'CallbackProperties');
hJTree.MousePressedCallback= {@guiCallback_tree_mousePressed,sessionNum};
% ...
% Cell renderer ... Get a dummy color definition
bsc= jTree.getCellRenderer.getBackgroundSelectionColor;
jTree.getCellRenderer.setBackgroundSelectionColor(bsc.lightGray);
jTree.getCellRenderer.setBorderSelectionColor(bsc.lightGray);
% ...
treePath= jTree.getSelectionPath.getPath;
for i=2:length(treePath)
lable= char(treePath(i).getValue);
end
Further Java functions used:
hTreeNode
add, getChildCount, getChildAt, getValue, getLevel, getParent, setName, repaint
hTree
Position, NodeSelectedCallback, expand, collapse
getModel
usinginsertNodeInto, removeNodeFromParent
jTree
isExpanded, setSelectionPath, isPathSelected, scrollPathToVisible
- all called with argument
javax.swing.tree.TreePath("pathnode")