Bug 320951 - [Viewers] ContentViewer gives bad error message when widget is disposed
Summary: [Viewers] ContentViewer gives bad error message when widget is disposed
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2010-07-26 15:05 EDT by Micah Hainline CLA
Modified: 2020-02-02 19:46 EST (History)
4 users (show)

See Also:


Attachments
Patch v01 (1.98 KB, patch)
2010-09-07 07:10 EDT, Hitesh CLA
no flags Details | Diff
Patch v02 (1.93 KB, patch)
2010-09-10 11:56 EDT, Hitesh CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Micah Hainline CLA 2010-07-26 15:05:32 EDT
Build Identifier: 20100617-1415

When ComboViewers and other ContentViewers are disposed, they clear their content provider.  If setInput is called later, instead of failing with a widget disposed error, they throw an error related to having no content provider.  This sets the developer down the wrong track when debugging it.  Instead, we should add an additional check in ContentViewer to throw an SWT exception right before the line 

Assert.isTrue(getContentProvider() != null, "ContentViewer must have a content provider when input is set."); //$NON-NLS-1$


Reproducible: Always

Steps to Reproduce:
Create a ComboViewer with ArrayContentProvider, dispose it, then set a list of strings as input.
Comment 1 Hitesh CLA 2010-09-07 07:10:06 EDT
Created attachment 178310 [details]
Patch v01

Some of the other methods do check for the control's state. 

Boris, I gather that getControl()==null implies that the control has been disposed. Just had a mild doubt about it after looking at the patterns in the code...

Thanks.
Comment 2 Boris Bokowski CLA 2010-09-09 15:18:26 EDT
The check itself looks good to me, but we shouldn't use "SWT.error(SWT.ERROR_WIDGET_DISPOSED);" because that's usually a sign that you are using SWT in an invalid way. In this instance, I would do something like:

throw new IllegalStateException("Need an underlying widget to be able to set the input (has the widget been disposed?)");
Comment 3 Hitesh CLA 2010-09-10 11:23:07 EDT
(In reply to comment #2)
> The check itself looks good to me, but we shouldn't use
> "SWT.error(SWT.ERROR_WIDGET_DISPOSED);" because that's usually a sign that you
> are using SWT in an invalid way. In this instance, I would do something like:
> 
> throw new IllegalStateException("Need an underlying widget to be able to set
> the input (has the widget been disposed?)");

Thanks Boris. Sounds good to me, will make a new patch on monday.
Comment 4 Hitesh CLA 2010-09-10 11:56:42 EDT
Created attachment 178626 [details]
Patch v02

(In reply to comment #3)
> 
> Thanks Boris. Sounds good to me, will make a new patch on monday.

On second thought, the patch was rather simple; released it to CVS HEAD.
Comment 5 Hitesh CLA 2010-09-10 11:57:16 EDT
Marking as Fixed.
Comment 6 Hitesh CLA 2010-10-26 06:09:14 EDT
Verified in  I20101012-0800.
Comment 7 Eric Rizzo CLA 2012-03-27 22:09:45 EDT
I'm curious why checking the control was implemented in this change. The description talks about the ContentProvider being disposed, not the Control. Was any consideration given to backwards compatibility when this patch was accepted?
I'm asking because I'm upgrading an application to be based on Eclipse 3.7 (from 3.4 or 3.5) and some of the code used custom a "NullViewer" that had no visible Control. It worked perfectly before, but now runs into this IllegalStateException. It seems to me that the contract of ContentViewer was changed as a result of this change, breaking existing subclasses of ContentViewer.
Comment 8 Pierre Huttin CLA 2012-08-08 18:16:36 EDT
As the Eric Rizzo remarks, I'm also surprise by this fix because, because the SWT Control is optional as it's written in javadocs : 

"create SWT controls for viewer (in constructor) (optional)"

So why check in setInput method if the control exist or not and if it disposed ? I'm checking compatibilty of tools developped on version 3.4, and it's the only blocking point for us.

So this fix definitly change the contract of this class.
Comment 9 Paul Webster CLA 2012-08-13 15:10:00 EDT
(In reply to comment #7)
> I'm curious why checking the control was implemented in this change. The
> description talks about the ContentProvider being disposed, not the Control.

The problem was (as I read it) the widget was disposed (because the viewer was disposed) but the viewer was throwing an error about the content provider, causing people to look for incorrect setContentProvider(*) instead of the eager dispose.

But it seems to me that the current solution also causes problems.  I'll take any patches to fix.

PW
Comment 10 Eclipse Genie CLA 2020-02-02 19:46:32 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.