0

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 using insertNodeInto, removeNodeFromParent

jTree

  • isExpanded, setSelectionPath, isPathSelected, scrollPathToVisible
  • all called with argument javax.swing.tree.TreePath("pathnode")
Community
  • 1
  • 1
Domenico
  • 43
  • 6
  • I have added a statement why my question is different than the similar one already answered – Domenico Jan 08 '17 at 11:36
  • Words like _sporadic_ always make me think of [_incorrect synchronization_](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html); diagnostics cited [here](http://stackoverflow.com/q/7787998/230513). – trashgod Jan 08 '17 at 12:02
  • I agree, but Matlab is not threaded from a user point of view, and I all I do is calling m-functions (and add/remove node Java functions) one after the other. I already added "pauses" of 30ms after issuing a Java command to give "Java" time to refresh the tree, before issuing another Java command but it didn't help. – Domenico Jan 08 '17 at 12:18
  • 1
    Sorry, either MATLAB _does_ run on the event dispatch thread, thus blocking it, or MATLAB does _not_ run on the event dispatch thread, thus requiring synchronization. – trashgod Jan 08 '17 at 12:59
  • The latter is the case, but MATLAB doesn't care at all about synchronisation of user-called Java objects. And myself as a simple user, which does not know anything about Java and synchronisation, only wanting a "tree" in a MATLAB figure to add nodes and remove nodes is overstrained with these tasks ... may be also a reason why this undocumented function will remain undocumented. To come back, all I know I can do from MATLAB side is using "pauses". – Domenico Jan 08 '17 at 13:32
  • 1
    @Domenico Are you calling any java methods directly? If so you can call them from [within the EDT](https://www.mathworks.com/help/matlab/ref/javamethodedt.html) – Suever Jan 08 '17 at 15:13
  • @Suever, a list of used functions have been added to the original post. I tried to understand the linked MATLAB EDT-function but I did not succeed. – Domenico Jan 08 '17 at 17:42
  • @Domenico, you should [read this](http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt) – nirvana-msu Jan 12 '17 at 16:37

0 Answers0