| Summary: | GraphViewer#findGraphItem throws ArrayIndexOutOfBoundsException if it can't find passed element | ||
|---|---|---|---|
| Product: | [Tools] GEF | Reporter: | Stefan Tucker <stefan.tucker> |
| Component: | GEF-Legacy Zest | Assignee: | Ian Bull <irbull> |
| Status: | RESOLVED FIXED | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | gerald, steeg, zoltan.ujhelyi |
| Version: | 3.4 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows Server 2003 | ||
| Whiteboard: | |||
I tested the issue right now and it is fixed in the current Git version of Zest 2.0. Thanks, verified this works in Zest 2.0 master with a unit test: http://git.eclipse.org/c/gef/org.eclipse.zest.git/commit/?id=00b35e623a6a102cade9a52afaddf62b1db29b32 |
Build ID: I20080523-0100 Steps To Reproduce: Call GraphViewer#findGraphItem(new Integer(5)). It should return null, but it throws ArrayIndexOutOfBoundsException instead. More information: If you call GraphViewer#findGraphItem() and pass an object it can't find in the graph, the findItems() method returns NO_WIDGETS, which is defined as "new Widget[0]." public GraphItem findGraphItem(Object element) { Widget[] result = findItems(element); return (result.length == 0 && result[0] instanceof GraphItem) ? null : (GraphItem) result[0]; } The problem is that if the returned array is of length 0, findGraphItem() accesses the first element. There's no first element (because the array's length is 0), so it throws an exception. The return statement should probably be: if ((result.length > 0) && (result[0] instanceof GraphItem)) return (GraphItem) result[0]; else return null;