Project: SWT
Bug 147423 NPE when removing an item from a Table with custom draw hooks
Reported: 2006-06-16 06:37:35 | Status: resolved fixed

We are using a Table with hooks to handle SWT.MeasureItem and SWT.PaintItem. When an item is being deleted from this table, a NPE is thrown because getBounds is invoked on an already disposed TableItem. The stack trace looks as follows: Thread [main] (Suspended (exception NullPointerException)) TableItem.getBounds(int, int, boolean, boolean, boolean, boolean, int) line: 234 Table.sendMeasureItemEvent(TableItem, int, int, int) line: 2904 Table.CDDS_SUBITEMPREPAINT(int, int) line: 481 [ ... removed ... ] Table.remove(int[]) line: 2445 A bit more detailed: 1) The item is being released and OS.LVM_DELETEITEM sent afterwards 2) This leads to Table.CDDS_SUBITEMPREPAINT being called, which in turn sends out a MeasureItem event 3) sendMeasureItemEvent will call item.getBounds on the already disposed item 4) getBounds accesses item.parent, which is null, because the item is disposed --- 1) Table.remove(int[]) line: 2445 --- if (item != null && !item.isDisposed ()) item.release (false); ignoreSelect = ignoreShrink = true; int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0); --- 2) Table.CDDS_SUBITEMPREPAINT(int, int) line: 481 --- if (hooks (SWT.MeasureItem)) { sendMeasureItemEvent (item, nmcd.dwItemSpec, nmcd.iSubItem, nmcd.hdc); if (isDisposed () || item.isDisposed ()) return null; } --- 3) Table.sendMeasureItemEvent(TableItem, int, int, int) line:2904 --- RECT itemRect = item.getBounds (row, column, true, true, false, false, hDC); --- 4) TableItem.getBounds(int, int, boolean, boolean, boolean, boolean, int) line: 234 --- int columnCount = parent.getColumnCount ();

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java