Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 377031

Summary: Empty/broken workbench.xmi file makes workspace unusable
Product: [Eclipse Project] Platform Reporter: Oleg Besedin <ob1.eclipse>
Component: UIAssignee: Oleg Besedin <ob1.eclipse>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: tom.schindl
Version: 4.2   
Target Milestone: 4.2 M7   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Error log none

Description Oleg Besedin CLA 2012-04-17 16:48:48 EDT
While working on another bug I've got into a state where workbench.xmi file became empty. I could not duplicate that, I'd guess that there was either an exception on shutdown or I killed Eclipse instance while save was in progress.

At any rate, it turned out that having empty workbench.xmi file renders workspace unusable as Eclipse can not start.

The ResourceHandler has this construct:

try {
	resource = resourceSetImpl.getResource(uri, true);
} catch (Exception e) {
...
	resource = resourceSetImpl.getResource(uri, false);
}

but that does not work as the next line assumes (and has to assume) that the root element in the resource is an application:

MApplication theApp = (MApplication) applicationResource.getContents().get(0);
Comment 1 Oleg Besedin CLA 2012-04-17 16:53:55 EDT
Created attachment 214148 [details]
Error log
Comment 2 Oleg Besedin CLA 2012-04-17 16:55:36 EDT
I put a simple fallback clause to use application default model if the modified model can't be read. 

In 4.3 we should work on making model save and load safer.

Git reference:

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=fdf4db780aacd85623c995e81788979e721fb568
Comment 3 Oleg Besedin CLA 2012-05-01 11:40:10 EDT
Verified using I20120430-1800.
Comment 4 Thomas Schindl CLA 2012-05-02 02:32:40 EDT
You can make file persist saver by using "Resource.OPTION_SAVE_ONLY_IF_CHANGED". From Ed on the newsgroup:

--------8<--------
You could use Resource.OPTION_SAVE_ONLY_IF_CHANGED which writes to either an in-memory or file system buffer and then compares it to the existing contents and replaces them only if they're different.  If the first part fails, it won't try the second part... 
--------8<--------
Comment 5 Thomas Schindl CLA 2012-05-02 04:17:07 EDT
File bug 378212 to use the saver persist method