Bug 185838 - [Parts] CoreExceptions are thrown as PartInitExceptions by TextFileDocumentProvider
Summary: [Parts] CoreExceptions are thrown as PartInitExceptions by TextFileDocumentPr...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC All
: P3 major (vote)
Target Milestone: 3.4 M4   Edit
Assignee: Boris Bokowski CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-07 15:22 EDT by Tod Creasey CLA
Modified: 2008-06-03 08:54 EDT (History)
3 users (show)

See Also:


Attachments
Patch (7.67 KB, patch)
2007-05-10 15:47 EDT, Tod Creasey CLA
no flags Details | Diff
Patch for Platform Text (1.55 KB, patch)
2007-05-15 08:47 EDT, Dani Megert CLA
no flags Details | Diff
Nicer error part (45.94 KB, image/png)
2007-11-13 11:26 EST, Dani Megert CLA
no flags Details
Improved error handling with nicer look (11.90 KB, patch)
2007-11-13 11:31 EST, 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 Tod Creasey CLA 2007-05-07 15:22:30 EDT
M7

If there is a CoreException opening a TextFileDocumentProvider it is forwarded as a PartInitException which is shown to the user as an unhandled exception (we show the dialog and the error part). This makes CoreExceptions look similar to problems like NPEs.

In 3.2.2 we got a nice editor with a blue line that said the file did not exist - I have checked and it was an instance of CompilationUnitEditor with no exception throen

STEPS
1) Create a project with more files than can be displayed in the editor area
2) Open all of the editors (so that there will be some EditorReferences on restart)
3) Shut down and restart
4) Delete the project

Every time you click on an editor reference you will get

!ENTRY org.eclipse.ui 4 0 2007-05-07 17:56:51.188
!MESSAGE Unable to create editor ID org.eclipse.jdt.ui.CompilationUnitEditor: The file does not exist.
!STACK 1
org.eclipse.core.runtime.CoreException: The file does not exist.
	at org.eclipse.core.internal.filebuffers.ResourceFileBuffer.create(ResourceFileBuffer.java:237)
	at org.eclipse.core.internal.filebuffers.TextFileBufferManager.connect(TextFileBufferManager.java:109)
	at org.eclipse.ui.editors.text.TextFileDocumentProvider.createFileInfo(TextFileDocumentProvider.java:553)
	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.createFileInfo(CompilationUnitDocumentProvider.java:932)
	at org.eclipse.ui.editors.text.TextFileDocumentProvider.connect(TextFileDocumentProvider.java:472)
	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.connect(CompilationUnitDocumentProvider.java:1167)
	at org.eclipse.ui.texteditor.AbstractTextEditor.doSetInput(AbstractTextEditor.java:3932)
	at org.eclipse.ui.texteditor.StatusTextEditor.doSetInput(StatusTextEditor.java:190)
	at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.doSetInput(AbstractDecoratedTextEditor.java:1224)
	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.internalDoSetInput(JavaEditor.java:2161)
	at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.doSetInput(JavaEditor.java:2134)
	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.doSetInput(CompilationUnitEditor.java:1312)
	at org.eclipse.ui.texteditor.AbstractTextEditor$19.run(AbstractTextEditor.java:2995)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:369)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:313)
	at org.eclipse.jface.window.ApplicationWindow$1.run(ApplicationWindow.java:758)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
	at org.eclipse.jface.window.ApplicationWindow.run(ApplicationWindow.java:755)
	at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2437)
	at org.eclipse.ui.texteditor.AbstractTextEditor.internalInit(AbstractTextEditor.java:3013)
	at org.eclipse.ui.texteditor.AbstractTextEditor.init(AbstractTextEditor.java:3040)
	at org.eclipse.ui.internal.EditorManager.createSite(EditorManager.java:794)
	at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:649)
	at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:426)
	at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:592)
	at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:299)
	at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:179)
	at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:268)
	at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
	at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:395)
	at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1242)
	at org.eclipse.ui.internal.PartStack.handleDeferredEvents(PartStack.java:1210)
	at org.eclipse.ui.internal.LayoutPart.deferUpdates(LayoutPart.java:400)
	at org.eclipse.ui.internal.PartSashContainer.handleDeferredEvents(PartSashContainer.java:1380)
	at org.eclipse.ui.internal.LayoutPart.deferUpdates(LayoutPart.java:400)
	at org.eclipse.ui.internal.WorkbenchPage.handleDeferredEvents(WorkbenchPage.java:1338)
	at org.eclipse.ui.internal.WorkbenchPage.deferUpdates(WorkbenchPage.java:1328)
	at org.eclipse.ui.internal.WorkbenchPage.closeEditors(WorkbenchPage.java:1302)
	at org.eclipse.ui.internal.WorkbenchPage.closeEditor(WorkbenchPage.java:1366)
	at org.eclipse.ui.texteditor.AbstractTextEditor$23.run(AbstractTextEditor.java:4032)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:123)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3650)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3287)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2365)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2329)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2204)
	at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:153)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:615)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:497)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:436)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1162)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1137)
!SUBENTRY 1 org.eclipse.core.filebuffers 4 0 2007-05-07 17:56:51.188
Comment 1 Dani Megert CLA 2007-05-08 06:07:00 EDT
Yep, the Platform Text code has changed (got fixed) in that area but the real problem that surfaces now is a Platform UI bug of which it has at least one duplicate already. Now that you filed it once again, maybe it gets fixed in a reasonable time frame ;-)

Just look at the stack trace. There is:
EditorManager.createSite(...) which calls IEditorPart.init(...)

And this method is spec'ed that clients should throw a PartInitException when the editor cannot be initialized. Now, how Platform UI handles this exception is completely Platform UI business.

See also bug 112277.
Comment 2 Dani Megert CLA 2007-05-08 06:17:09 EDT
See also bug 185660 for another instance where the PartInitException is (correctly) created and thrown by Platform UI but then unfriendly handled by logging it and showing error dialogs.
Comment 3 Dani Megert CLA 2007-05-08 08:24:50 EDT
I would expect that not every editor implementer has to handle such cases on
its own and write code can show errors inside the editor area.

Having said that. If Platform UI can't address this for 3.3 I can add a
workaround in Platform Text to get the same behavior as in 3.3. Let me know.
Comment 4 Dani Megert CLA 2007-05-08 09:11:20 EDT
FYI: the code that shows the status for text editors can be found in StatusTextEditor.
Comment 5 Mike Wilson CLA 2007-05-08 13:38:54 EDT
The real problem here is in the definition of "error". Users would not expect a an editor on a file that does not exist to be an error that should be displayed with a walkback (i.e. walkbacks in views/editors should *never* happen as part of the normal functioning of Eclipse). They would expect either that the editor would be closed, or it would be left in a state that the file could be recreated, by saving it again. Given our current architecture, the former would be a better choice, so all open editors (even ones that have not been realized) should be closed when their editor inputs are removed from the workspace. If that's not possible, then a presentation like the one we had in 3.2 (i.e. with a simple message indicating that the file is gone) is much better than showing them a walkback. 

The problem with simply having the UI catch the exception and do this is that it doesn't allow us to distinguish between the above case and an actual unexpected situation caused by a coding error. Currently, we assume that if you let it through to us, it was a *serious* problem (i.e. one for which a walkback should be shown).

Comment 6 Dani Megert CLA 2007-05-09 03:56:00 EDT
Mike, the case where the input is no longer valid (i.e. cannot be recreated) is completely handled by Platform UI where the result returned by the IElementFactory is thrown as PartInitException (see bug 185660) by Platform UI code. Nothing any client can do/protect against this. And yes, I agree that there shouldn't be a dialog for this but a nice in-place message.

Now, for the case of FileEditorInput the corresponding factory in UI land does not return 'null' for FileEditorInputs whose files no longer exist but a file editor input pointing to the deleted file and hence the client code (e.g. Platform Text) is called even though it is already clear at that time that the given input doesn't exist - this shouldn't be done as there's no chance a client can ever open its editor. Now, the next step where a client comes into play is: IEditorPart.init(...) which clearly specs:

@exception PartInitException if this editor was not initialized successfully

It doesn't say anything about whether the client has to handle minor issues on its own and personally I wouldn't claim that my editor is successfully initialized if the file didn't exist, would you?

I can put the workaround back in, but as said above my code shouldn't be called in the first place and every other client that has a factory that correctly returns 'null' will also run into this and also every client that considers its editor as not correctly initialized when the file is missing and hence - according to the Javadoc - throws the PartInitException.
Comment 7 Dani Megert CLA 2007-05-09 16:58:27 EDT
Just in case: I would have a patch ready that restores the 3.2.x behavior for textual editors regarding non-existing files.
Comment 8 Mike Wilson CLA 2007-05-10 10:17:49 EDT
As of the latest builds, we are now showing an error part, rather than popping up the error dialog for this case. This is fine for *real* errors, but not a good solution for something that a user can easily make happen with normal workflows.

Re-assigning to Boris...

1) Boris, please determine whether we can actually get the unrealized editor tabs to close automatically. If that's true, then showing the editor part for other cases is acceptable.

2) If we can not make the tabs go away (i.e. don't do anything yet, Dani), then Dani will have to put back his workaround for 3.3 and the UI team will take ownership of the equivalent for 3.3.1 (or 3.4 depending whether new API is required).
Comment 9 Mike Wilson CLA 2007-05-10 10:24:34 EDT
s/showing the editor part/showing the error part/

Comment 10 Tod Creasey CLA 2007-05-10 15:47:52 EDT
Created attachment 66765 [details]
Patch

Here is an implementation that listens for resource deletes and then clears out the  stale references.

This turned out to be more involved then I would have liked so I would prefer we did this for 3.3.1 and had Dani release his workaround for 3.3.0.
Comment 11 Boris Bokowski CLA 2007-05-10 16:22:30 EDT
I looked at the patch and agree with Tod that this would be a high-risk change.  I don't have any other idea for how this bug could be fixed in a simpler way.

If we decide to put this in, for 3.3, or 3.3.1, here are my comments from looking at the code:
- Resource change events can happen on a non-UI thread, the patch assumes that all notifications happen on the UI thread.
- The logic dealing with deleted containers assumes that the container is a project.
Comment 12 Dani Megert CLA 2007-05-14 11:25:44 EDT
Note that my patch would only work for the case where core resources indeed threw a file not found exception (e.g. when the whole project is gone). In the case of e.g. just a file being deleted we do not get such an exception - instead we get an  exception that the content description could not be retrieved (FAILED_DESCRIBING_CONTENTS) and I have no clue why this happened and hence this will show up inside the editor. On the other hand file.exists() still returns true and hence I cannot special-case this on my end.
Comment 13 Dani Megert CLA 2007-05-15 08:40:47 EDT
Filed bug 186977 for the editor input factory problem.
Filed bug 186984 for the problem when getting the charset.
Comment 14 Dani Megert CLA 2007-05-15 08:47:28 EDT
Created attachment 67221 [details]
Patch for Platform Text

This patch fixes the problem on Platform Text side and restores the previous behavior and also works around the problems mentioned in comment 12. The fix also handles external files that got deleted.

Can one of you guys vote for it for RC1?
Comment 15 Tod Creasey CLA 2007-05-15 10:43:15 EDT
+1 from me for Dani's patch
Comment 16 Dani Megert CLA 2007-05-15 10:53:15 EDT
Thanks Tod. I've committed the patch and suggest to defer this bug to 3.4.
Comment 17 Dani Megert CLA 2007-11-12 09:34:33 EST
As of 3.4 M3 there are still various cases where this can happen and it also seems that statement in comment 8 is not true using 3.4 M3:
  "As of the latest builds, we are now showing an error part, rather than popping
  up the error dialog for this case. "
I see a dialog, a log entry and finally the error shown inside your error status editor. This editor also takes away the part title so that users can no longer see the file name.

Note that due to other code changes my workaround is no longer triggered.
Comment 18 Boris Bokowski CLA 2007-11-12 12:08:23 EST
(In reply to comment #17)
> As of 3.4 M3 there are still various cases where this can happen

Do you mean more cases than the one described by comment 0?
Comment 19 Dani Megert CLA 2007-11-13 02:12:10 EST
>Do you mean more cases than the one described by comment 0?
1. everything with the same scenario but not text editor (e.g. class file editor
   PDE, etc.
2. see comment 12
Comment 20 Dani Megert CLA 2007-11-13 11:26:00 EST
Created attachment 82777 [details]
Nicer error part
Comment 21 Dani Megert CLA 2007-11-13 11:31:05 EST
Created attachment 82778 [details]
Improved error handling with nicer look

This patch
- ensures that we do not show a superfluous dialog (as everything is already 
  available via error status part
- creates the attached nicer look for the error status part (for editors and 
  views)
- fixes the problem of disappearing tab title when the NullEditorInput is used

Let me know if you like it and I'll commit it to HEAD.
Comment 22 Boris Bokowski CLA 2007-11-13 15:03:12 EST
Looks good, thanks a lot!
Comment 23 Dani Megert CLA 2007-11-14 03:05:15 EST
OK, I've committed the patch to HEAD. We should still improve the handling of deleted files as this is not Text specific.
Comment 24 Boris Bokowski CLA 2008-05-21 12:50:07 EDT
Dani, can we close this one as fixed and track the remaining issue by bug 186977? Could you check if bug 186977 accurately captures what needs to be done?
Comment 25 Dani Megert CLA 2008-05-22 16:09:06 EDT
>Dani, can we close this one as fixed 
Yup.
Comment 26 Philipe Mulet CLA 2008-06-03 06:22:10 EDT
pls remember to set the target milestone
Comment 27 Boris Bokowski CLA 2008-06-03 08:54:19 EDT
The fix for this went in quite some time ago. I am guessing M4.