Bug 81514 - [EditorMgmt] setInput should defend against null
Summary: [EditorMgmt] setInput should defend against null
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: 3.6 M1   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on: 99715
Blocks:
  Show dependency tree
 
Reported: 2004-12-17 09:10 EST by Dani Megert CLA
Modified: 2017-09-13 10:31 EDT (History)
6 users (show)

See Also:


Attachments
Patch adding Asserts (1.52 KB, patch)
2009-06-15 08:41 EDT, Dani Megert CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2004-12-17 09:10:48 EST
I200412162000

IEditorPart.getEditorInput() does not spec (Javadoc) to return null but it does
so after the editor has been closed. Since getEditorSite() explicitly mentions
the null case we assumed that IEditorPart.getEditorInput() never returns null.
Comment 1 Douglas Pollock CLA 2005-01-11 07:14:17 EST
Platform UI's code base is wildly inconsistent in its declaration of null 
return values and parameters.  I've heard conflicting stories as to what the 
policy should be.  I'll try to make this explicit for 3.1 -- either way. 
Comment 2 Dani Megert CLA 2005-01-11 07:18:32 EST
> I've heard conflicting stories
See: http://www.eclipse.org/articles/Article-API%20use/eclipse-api-usage-rules.html
Comment 3 Douglas Pollock CLA 2005-01-12 13:37:03 EST
I know about that doc, but I still *hear* conflicting stories.  I don't 
believe that everyone knows about this doc.  Either that or some people have 
decided to disagree with it. 
 
Personally, I feel it should always be explicit.  That way plug-in developers 
know that a comment wasn't simply forgotten.  But that's personal taste. 
 
Comment 4 Douglas Pollock CLA 2005-06-10 08:37:40 EDT
I won't commit this for 3.1 RC2, but plan on doing it for 3.1 RC3.

Nick: I just want to clarify something.  AbstractTextEditor calls
EditorInput.setInput(null) in its dispose method.  This causes the editor input
to violate the specification for IEditorInput.getEditorInput(), which insists
that it not be null.  Is it strictly necessary for AbstractTextEditor to be
setting the input to null in its dispose?
Comment 5 Dani Megert CLA 2005-06-10 08:56:26 EDT
True, we set it to null. This seems not be needed when looking at the
implementation. Since this bug is minor and we should concentrate on critical
bugs I would not change that code now (Platform UI and Text side).
Comment 6 Nick Edgar CLA 2005-06-10 10:01:44 EDT
Agree with Dani's assessment.  We should probably clear the input ourselves in
EditorPart.dispose(). cc'ing Stefan to confirm.
Comment 7 Douglas Pollock CLA 2005-06-10 10:13:29 EDT
This bug seems to be changing quite a bit.  The original question was whether
IEditorPart.getEditorInput() could return null.  It seems the consensus is
"yes".  As such, I will fix up the doc in 3.1 RC3.

If there are further questions about whether we should be doing stuff for free
when disposing of parts, then perhaps we should open another bug?
Comment 8 Nick Edgar CLA 2005-06-10 10:19:12 EDT
Sorry, my suggestion to clear it does go counter to the current spec.
It seems like we're only returning null due to AbstractTextEditor setting it to
null (contrary to current spec).
Please check with Stefan before making any change, as he has been trying to
solidify the spec and behaviour in this area.
If we change it now (even if to match current behaviour), it will need to be
documented in the migration guide.

Comment 9 Stefan Xenos CLA 2005-06-10 16:45:12 EDT
getEditorInput cannot return null. setInput cannot accept null. The spec has
never permitted either of these cases, and I don't see any good reason to make
this breaking change.

However, the spec on dispose() says it must be the last method called on the
part... so it isn't strictly necessary for a part to respect its public contract
after the call to dispose.

The only bug here is that AbstractTextEditor is calling
EditorInput.setInput(null). We should be protecting against this with an Assert.
Comment 10 Douglas Pollock CLA 2005-06-13 12:15:41 EDT
I have opened Bug 99715 with Platform Text, asking them to stop calling
setInput(null).  When that bug is fixed, we can add an assert to our own code.

This is not critical for 3.1.
Comment 11 Michael Van Meekeren CLA 2006-04-21 13:19:29 EDT
Moving Dougs bugs
Comment 12 Tod Creasey CLA 2006-05-01 11:21:27 EDT
Deferring
Comment 13 Ducky Sherwood CLA 2008-01-10 21:21:38 EST
This is perhaps related, but maybe not.  I wasn't sure where to put this.

Neither AbstractTextEditor.setInput(IEditorInput) nor the chain of calls that it sets in motion set fTextEditor's editor input.  This means that the fTextEditor and the AbstractTextEditor can have a different opinion about which inputEditor they are associated with.

This doesn't seem to be breaking any features in stock Eclipse, but it caused me problems in some modifications I am doing to tab behaviour (for an experiment, not for release).
Comment 14 Dani Megert CLA 2008-01-11 03:47:18 EST
>fTextEditor's editor input
What you meant here?

If you find a bug report please just open a new bug with the details against Platform Text.
Comment 15 Mike Wilson CLA 2008-04-12 11:41:11 EDT
Ducky, you will need to follow Dani's suggestion. Your problem is definitely not related to the situation in this bug. 

Lowering the priority of this bug to reflect reality.
Comment 16 Boris Bokowski CLA 2009-06-12 13:00:21 EDT
(mass update)
Removing target milestone, this bug was targeted at a milestone in the past.
Comment 17 Dani Megert CLA 2009-06-15 08:40:26 EDT
Boris I suggest to finally fix this early in the release by adding an Assert. In addition we could add an entry to the migration guide that this will be enforced in 3.6.
Comment 18 Dani Megert CLA 2009-06-15 08:41:36 EDT
Created attachment 139167 [details]
Patch adding Asserts
Comment 19 Boris Bokowski CLA 2009-06-18 07:48:07 EDT
Marking for M1 to make sure this does not fall through the cracks. I haven't thought about this enough to say whether I agree with you, Dani, that we should make this change in 3.6.
Comment 20 Dani Megert CLA 2009-06-18 11:19:00 EDT
OK, I digged a bit in the UI code and found this:
1. org.eclipse.ui.internal.PartTester.testEditor(IEditorPart) which gets called before an editor is opened blows up if the editor input is 'null', hence there can't be any useful/working client out there that sets 'null'.
2. in the Platform UI code you'll see that at some places IEditorPart.getEditorInput() checks for 'null' and at others it does not, which again tells us that it would have blown off long time ago when the input had been set to 'null'.
Comment 21 Boris Bokowski CLA 2009-06-22 12:50:33 EDT
> 1. org.eclipse.ui.internal.PartTester.testEditor(IEditorPart) which gets called
> before an editor is opened blows up if the editor input is 'null', hence there
> can't be any useful/working client out there that sets 'null'.

Based on this, it looks like the proposed change is safe. Let's do it for M1. Dani, do you want to release the change when HEAD is open again?
Comment 22 Dani Megert CLA 2009-06-23 02:06:02 EDT
>Dani, do you want to release the change when HEAD is open again?
Sure. We (Text, JDT have it open already) is this true for Platform UI as well?
Comment 23 Boris Bokowski CLA 2009-06-23 10:37:49 EDT
(In reply to comment #22)
> >Dani, do you want to release the change when HEAD is open again?
> Sure. We (Text, JDT have it open already) is this true for Platform UI as well?

I just sent a message to platform-ui-dev saying that HEAD is open for 3.6.
Comment 24 Dani Megert CLA 2009-06-24 04:01:14 EDT
Fixed in HEAD.
Available in builds > N20090623-2000.