Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 243723

Summary: ArrayIndeOfBounds Exception on org.eclipse.zest.core.viewers.GraphViewer.findGraphItem(Object)
Product: [Tools] GEF Reporter: marco <marcodonati>
Component: GEF-Legacy ZestAssignee: Ian Bull <irbull>
Status: RESOLVED FIXED QA Contact:
Severity: critical    
Priority: P3 CC: ahunter.eclipse
Version: 3.4   
Target Milestone: 3.5.0 (Galileo) M3   
Hardware: PC   
OS: Linux   
Whiteboard:

Description marco CLA 2008-08-11 06:08:41 EDT
This is the code:

public GraphItem findGraphItem(Object element) {
		Widget[] result = findItems(element);
		return (result.length == 0 && result[0] instanceof GraphItem) ? null : (GraphItem) result[0];
	}


probably the Exception was throw because when result.length==0.

I think it would be:

public GraphItem findGraphItem(Object element) {
   Widget[] result = findItems(element);
   return (result.length == 0) ? null : (result[0] instanceof GraphItem) ? (GraphItem) result[0] : null;
}
Comment 1 marco CLA 2008-08-11 06:10:57 EDT
The java doc for this method report this note:

	 * Note: This method returns an internal interface (GraphItem). You should
	 * be able to cast this to either a IGraphModelNode or IGraphModelConnection
	 * (which are also internal). These are internal because this API is not
	 * stable. If use this method (to access internal nodes and edges), your
	 * code may not compile between versions.

I think this method it would be public and returning non-internal classes or interfaces.
tnx
cheers
Marco
Comment 2 Ian Bull CLA 2008-10-14 15:57:14 EDT
I think the code should be:
		return (result.length == 0 || !(result[0] instanceof GraphItem)) ? null : (GraphItem) result[0];
		
If the length is 0 or the item is not a GraphItem, return null, otherwise, return the item.

The API problem is no longer an issue.