Skip to content

Tag: EMF

Getting Rid of the Ugly “Resource is out of sync” Message

While working with my OPM GEF editor, I sometimes saw the current exception in the eclipse console:

!ENTRY org.eclipse.core.resources 4 1 2011-09-04 12:30:26.667
!MESSAGE Core exception while retrieving the content description
org.eclipse.core.internal.resources.ResourceException: Resource is out of sync with the file system: '/OPP Development/modeling/OPPEditorMain.opm'.
	at org.eclipse.core.internal.resources.File.getContentDescription(
	at org.eclipse.core.internal.propertytester.FilePropertyTester.testContentType(

While this was bothersome, it didn’t affect the editor’s contents and didn’t bother, so I did nothing to fix the problem. But now that I am working more with the editor itself and not developing it, it seemed to happen more often, and there was a concrete way to reproduce it: after modifying a model and saving it, every time I opened it the exception occurred. It stopped occurring when I refreshed the workspace.

No (short) google researched turned out a good solution and so I started reading more of the GEF logic example code where this didn’t happen, but this code didn’t use EMF, so it didn’t help. But after some thinking, the problem popped up: while I was saving the model in the resource, this was an EMF resource, and not an eclipse resource, therefore eclipse was not aware that the file was changed. Solution? simply inform the workbench that the file was changed after I saved it. This was easily done by calling the IResource.touch method on the model file after saving it:

    public void doSave(IProgressMonitor monitor) {
        if(opdResource == null) {

        try {
        } catch (IOException e) {
            // TODO do something smarter.
        } catch (CoreException e) {
            // TODO do something smarter.

And the exception is gone 🙂