Community
Participate
Working Groups
Table.getColumn(int) Should check for a null columns field before trying to access the array elements. Scenario: If the table is disposing it is not flaged as disposed until after dispose events are fired. A listener to the table dispose may try to dispose of its self and in doing so may try to retreive table items (as in my case). The listener would not know from calling table.isDisposed() whether the table is being disposed. In such a case, either the table should be marked as disposed, or a call to getColumn(int) should return null.
SN shouldn't the Table still be in its intact state when Dispose listeners are invoked? Snippet: public static void main (String [] args) { Display display = new Display (); final Shell shell = new Shell (display); shell.setBounds(10,10,200,200); final Table table = new Table(shell, SWT.NONE); table.setBounds(10,10,160,100); new TableColumn(table,SWT.NONE); new TableColumn(table,SWT.NONE); new TableColumn(table,SWT.NONE); Button button = new Button (shell, SWT.PUSH); button.setBounds(10,130,60,30); button.setText("Dispose"); button.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { table.dispose(); } }); table.addListener(SWT.Dispose, new Listener() { public void handleEvent(Event event) { table.getColumn(1); } }); shell.open (); while (!shell.isDisposed()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); }
Disposing happens from the leaves to the roots. At the time that the table is disposed, the table items and columns have already been disposed. There is a very old problem report that captures this "bug". In order to really fix it, we would have to traverse the widget tree 3 times (making dispose() slow). *** This bug has been marked as a duplicate of 4416 ***