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

Bug 283263

Summary: ArrayIndexOutofBoundsException when clicking on the Pixel Row just below the Table Header.
Product: [RT] RAP Reporter: Jeff <jeff.lau>
Component: RWTAssignee: Project Inbox <rap-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: daniel.zweifel
Version: 1.2   
Target Milestone: 1.3 M1   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Bugfix none

Description Jeff CLA 2009-07-12 22:20:19 EDT
As an example let say I have a table with 2 rows and the row height is 20 pixels each.  The first row is the header, since the height is 20 pixels the y coordinate goes from 0 to 19 and the y coordinate of the 2nd row goes from 20 to 39.

If I click on the table where the y coordinate = 20, I would get a ArrayIndexOutofBoundsException in my log, with the following stacktrace:

java.lang.ArrayIndexOutOfBoundsException: -1
	at org.eclipse.swt.widgets.Table._getItem(Table.java:2101)
	at org.eclipse.swt.widgets.Table.getItem(Table.java:676)
	at org.eclipse.jface.viewers.TableViewer.getItemAt(TableViewer.java:197)
	at org.eclipse.jface.viewers.ColumnViewer.getViewerRow(ColumnViewer.java:150)
	at org.eclipse.jface.viewers.ColumnViewer.getCell(ColumnViewer.java:133)
	at org.eclipse.jface.viewers.ColumnViewer.handleMouseDown(ColumnViewer.java:649)
	at org.eclipse.jface.viewers.ColumnViewer.access$0(ColumnViewer.java:648)
	at org.eclipse.jface.viewers.ColumnViewer$1.mouseDown(ColumnViewer.java:88)


The problem I believe is with the following code in the Table class.

  public TableItem getItem( final Point point ) {
    checkWidget();
    TableItem result = null;
    int headerHeight = getHeaderHeight();
    Rectangle itemArea = getClientArea();
    itemArea.y += headerHeight;
    if( itemArea.contains( point ) ) {
      int itemHeight = getItemHeight();
      int index = ( ( point.y - headerHeight ) / itemHeight ) - 1;
      if( point.y == 0 || point.y % itemHeight != 0 ) {
        index++;
      }
      index += topIndex;
      if( index < itemCount ) {
        result = _getItem( index );
      }
    }
    return result;
  }

The itemArea contains the point which is correct, but the calculation of the index is incorrect.  In this case where point.y = 20, if u step through the above code u will see the index value at the end is -1, causing the exception.  (topIndex is 0)
Comment 1 RĂ¼diger Herrmann CLA 2009-07-14 19:25:19 EDT
Created attachment 141584 [details]
Bugfix
Comment 2 RĂ¼diger Herrmann CLA 2009-07-14 19:26:23 EDT
Changes are in CVS HEAD.
Comment 3 Ivan Furnadjiev CLA 2009-09-22 03:27:27 EDT
*** Bug 289975 has been marked as a duplicate of this bug. ***