Community
Participate
Working Groups
If refresh (just as an example) is called but the widget is already disposed the following exception occurs. It would be nice if TreeViewer#getSelection() would check if widget is disposed and if yes simply returns an empty selection org.eclipse.swt.SWTException: Widget is disposed at org.eclipse.swt.SWT.error(SWT.java:4720) at org.eclipse.swt.SWT.error(SWT.java:4635) at org.eclipse.swt.SWT.error(SWT.java:4606) at org.eclipse.swt.widgets.Widget.error(Widget.java:550) at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:470) at org.eclipse.swt.widgets.Tree.getSelection(Tree.java:1923) at org.eclipse.jface.viewers.TreeViewer.getSelection(TreeViewer.java:231) at org.eclipse.jface.viewers.TreeViewer.setSelection(TreeViewer.java:308) at org.eclipse.jface.viewers.AbstractTreeViewer.setSelectionToWidget(AbstractTreeViewer.java:2561) at org.eclipse.jface.viewers.AbstractTreeViewer.setSelectionToWidget(AbstractTreeViewer.java:3016) at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1400) at org.eclipse.jface.viewers.TreeViewer.preservingSelection(TreeViewer.java:363) at org.eclipse.jface.viewers.StructuredViewer.preservingSelection(StructuredViewer.java:1354) at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1454) at org.eclipse.jface.viewers.ColumnViewer.refresh(ColumnViewer.java:526) at org.eclipse.jface.viewers.StructuredViewer.refresh(StructuredViewer.java:1413)
I'm not completely sure here what the right solution is. Also other methods in TreeViewer call the widget without check the Tree state. While it would be easy to fix this special and valid case, I'm wondering if other locations would be valid, too. And if, check them all or just with evidence that they cause issues like here?
@Karsten Thoms it's a little bit a question of how "nice" JFace is supposed to react to disposal, it I'm currently adding checks "outside" its just a little bit cumbersome to always call: >if(!treeViewer.getControl().isDisposed()) { > treeViewer.refresh(); >} I personally would favor to guard the user against all kinds of underlying widget disposal, but maybe this is too much and better be solved step-by-step. On the other hand one might argue that trying to use a viewer where the underlying widget is disposed is an error, its just a little bit odd to "decorate" dynamic doe all and always with all this "is EDT" "is not disposed" "is blablab" checks. So maybe the check should only go into refresh() and variants?
> So maybe the check should only go into refresh() and variants? This would improve the situation a bit. Let's go for it. Would you provide a patch?
(In reply to Karsten Thoms from comment #3) > > So maybe the check should only go into refresh() and variants? > > This would improve the situation a bit. Let's go for it. Would you provide a > patch? I would vote -1 for that, because it will hide valid errors and lead to inconsistent behavior of the JFace API, that now will allow working with disposed widgets. (In reply to Christoph Laeubrich from comment #2) > On the other hand one might argue that trying to use a viewer where the > underlying widget is disposed is an error The code in question will definitely not do what it is supposed to do and still think that everything is "OK", while in fact the code will operate on a "dead" widget. Having errors helps a lot to find bugs. So I would close this bug as won't fix.
Is it a bug do ignore a refresh of a no longer visble viewer? From the API point of view, the Viewer API does not declare any exception to be thrown from that method.