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
*/
    private IBaseLabelProvider labelProvider = null;
    /**
     * This viewer's label provider listener.
     * Note: Having a viewer register a label provider listener with
     * a label provider avoids having to define public methods
     * for internal events.
     */
    private final ILabelProviderListener labelProviderListener = new ILabelProviderListener() {
        public void labelProviderChanged(LabelProviderChangedEvent event) {
            ContentViewer.this.handleLabelProviderChanged(event);
        }
    };
    /**
     * Creates a content viewer with no input, no content provider, and a
     * default label provider.
     */
    protected ContentViewer() {
    }
    /**
     * Returns the content provider used by this viewer, 
     * or <code>null</code> if this view does not yet have a content
     * provider.
     * <p>
     * The <code>ContentViewer</code> implementation of this method returns the content
     * provider recorded is an internal state variable. 
     * Overriding this method is generally not required; 
     * however, if overriding in a subclass, 
     * <code>super.getContentProvider</code> must be invoked.
     * </p>