Bug 109281 [Viewers] ContentViewer does not null out input on handleDisposed
While tracking down a possible leak I were calling viewer.setInput(null) when viewer.getInput()!=null but that gave an assert exception because the ContentProvider had been nulled out in handleDisposed(). I suggest you also null out Input to keep the state consistent since the code actually call inputChanged as if input had been nulled out. protected void handleDispose(DisposeEvent event) { if (contentProvider != null) { contentProvider.inputChanged(this, getInput(), null); contentProvider.dispose(); contentProvider = null; input = null; // add this line for consistency } if (labelProvider != null) { labelProvider.removeListener(labelProviderListener); labelProvider.dispose(); labelProvider = null; } }
bundles/org.eclipse.jface/src/org/eclipse/jface/viewers/ContentViewer.java
* <p>
     * The <code>ContentViewer</code> implementation of this method calls <code>labelProviderChanged()</code>
     * to cause a complete refresh of the viewer.
     * Subclasses may reimplement or extend.
     * </p>
     */
    protected void handleLabelProviderChanged(LabelProviderChangedEvent event) {
        labelProviderChanged();
    }
    /**
     * Adds event listener hooks to the given control.
     * <p>
     * All subclasses must call this method when their control is
     * first established.
     * </p> 
     * <p>
     * The <code>ContentViewer</code> implementation of this method hooks 
     * dispose events for the given control.
     * Subclasses may override if they need to add other control hooks;
     * however, <code>super.hookControl</code> must be invoked.
     * </p>
     *
     * @param control the control
     */
    protected void hookControl(Control control) {
        control.addDisposeListener(new DisposeListener() {
            public void widgetDisposed(DisposeEvent event) {
                handleDispose(event);
            }
        });