Bug 245220 - Exception when selecting item, clearing table, and calling getSelection()
Summary: Exception when selecting item, clearing table, and calling getSelection()
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Nebula (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P1 major (vote)
Target Milestone: ---   Edit
Assignee: Chris Gross CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-08-26 04:54 EDT by Emil Crumhorn CLA
Modified: 2021-07-05 11:38 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Emil Crumhorn CLA 2008-08-26 04:54:30 EDT
This bug occurs due to the selection not getting cleared/checked internally prior to a submethod call is made.

To reproduce, simply follow this: 

1. Have some items in a table, select an item (or a cell)
2. Call removeAll() on the table through an action or menu, etc.
(at this point the selection is still in memory internally in the Grid)
3. Have a mouseDownListener on the table (easiest) and call table.getSelection().
4. Exception is thrown:

java.lang.IllegalArgumentException: Index out of bounds
	at org.eclipse.swt.SWT.error(SWT.java:3547)
	at org.eclipse.swt.SWT.error(SWT.java:3481)
	at org.eclipse.swt.SWT.error(SWT.java:3452)
	at org.eclipse.nebula.widgets.grid.Grid.getItem(Grid.java:1636)
	at org.eclipse.nebula.widgets.grid.Grid.getSelection(Grid.java:2161)

Suggested fix:

1. getSelection() in Grid.java should make a check to see how many items there are in the table before trying to call getItem(...). If table item list size is zero then the selection is obviously not valid. 
2. It seems removeAll() should clear selection on the table as well, however;

I'm not sure if the intention is to preserve selection despite an empty table, if so, at least a check to ignore an out of bounds selection should be made prior to calling getItem() so that no exception is thrown.

Workaround:

Create your own clear() method between your code and the table, in that method, call table.deselectAll() prior to calling removeAll().
Comment 1 Jake fisher CLA 2010-02-02 15:54:15 EST
This still seems to be a problem
Comment 2 Thomas Schindl CLA 2010-04-01 23:59:54 EDT
Released changes to prevent the Exception to CVS >= 20100402. Thanks Emil for the investigation and Jake for the heads up.