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

Bug 339900

Summary: Closing JPA project results in a deadlock if diagram editor is open
Product: [WebTools] Dali JPA Tools Reporter: Nan Li <nan.n.li>
Component: Diagram EditorAssignee: Petya Sabeva <petya.sabeva>
Status: VERIFIED FIXED QA Contact: Stefan Dimov <stefan.dimov>
Severity: major    
Priority: P3 CC: david_williams, jolene.moffitt, neil.hauge
Version: 3.0Flags: david_williams: pmc_approved+
stefan.dimov: pmc_approved? (raghunathan.srinivasan)
stefan.dimov: pmc_approved? (naci.dai)
stefan.dimov: pmc_approved? (deboer)
neil.hauge: pmc_approved+
stefan.dimov: pmc_approved? (kaloyan)
stefan.dimov: pmc_approved? (cbridgha)
stefan.dimov: review+
neil.hauge: review+
Target Milestone: 3.0 RC3   
Hardware: PC   
OS: Windows 7   
Whiteboard: PMC_approved
Bug Depends on: 345274    
Bug Blocks:    
Attachments:
Description Flags
Stack Trace
none
patch
none
proposed patch
none
Avoid deadlock
none
Patch for junit tests
none
Close JPA Editor before closing project
none
patch none

Description Nan Li CLA 2011-03-14 10:56:09 EDT
Build Identifier: I-3.3.0-20110305235707

1. With the diagram editor being opened, closing project cannot be done properly.
2. Closing the JPA project should close the diagram editor, but it does not.

Reproducible: Always

Steps to Reproduce:
1. Create a JPA project
2. Open the diagram editor
3. Try to close the JPA project -> Result 1
4. Open the diagram editor again
5. Create some entities and save
6. Try to close the JPA project -> Result 2

Result 1: A NPE is thrown saying "Problems occurred when invoking code from plug-in: "org.eclipse.core.resources"." The stack trace is attached.

Result 2: Closing project operation gets hung up saying the user operation is waiting for "Close Project" to complete. From this point on, all the operations will be waiting including closing Eclipse. I have to kill the Eclipse process through the Windows task manager.
Comment 1 Nan Li CLA 2011-03-14 10:58:10 EDT
Created attachment 191124 [details]
Stack Trace
Comment 2 Petya Sabeva CLA 2011-05-09 02:54:41 EDT
Created attachment 195037 [details]
patch

This patch fixes only the issue that comes as e Result 2, because I wasn't able to reproduce the first one...
Comment 3 Stefan Dimov CLA 2011-05-10 08:22:40 EDT
The patch works fine, but if the editor is dirty it should ask the user if she wants to save the changes before closing
Comment 4 Petya Sabeva CLA 2011-05-10 10:04:11 EDT
Created attachment 195215 [details]
proposed patch

Now if the editor is dirty while the project is trying to be closed, a "Save Resource" dialog appears...
Comment 5 Stefan Dimov CLA 2011-05-10 13:51:18 EDT
With the second patch at closing the project I often get:

org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.core.internal.resources.ResourceException: Resource '/rewrw/diagrams/rewrw.xmi' does not exist.)
	at org.eclipse.swt.SWT.error(SWT.java:4277)
	at org.eclipse.swt.SWT.error(SWT.java:4192)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:137)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4125)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3742)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException: org.eclipse.core.internal.resources.ResourceException: Resource '/rewrw/diagrams/rewrw.xmi' does not exist.
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:315)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject(ResourceSetImpl.java:216)
	at org.eclipse.graphiti.ui.editor.DiagramEditorInput.getEObject(DiagramEditorInput.java:674)
	at org.eclipse.graphiti.ui.editor.DiagramEditorInput.setEditorEditingDomain(DiagramEditorInput.java:569)
	at org.eclipse.graphiti.ui.editor.DiagramEditorInput.<init>(DiagramEditorInput.java:188)
	at org.eclipse.graphiti.ui.editor.DiagramEditorFactory.createElement(DiagramEditorFactory.java:205)
	at org.eclipse.ui.internal.NavigationHistoryEditorInfo.restoreEditor(NavigationHistoryEditorInfo.java:79)
	at org.eclipse.ui.internal.NavigationHistory.addEntry(NavigationHistory.java:371)
	at org.eclipse.ui.internal.NavigationHistory.access$10(NavigationHistory.java:355)
	at org.eclipse.ui.internal.NavigationHistory$2.run(NavigationHistory.java:202)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
	... 23 more
Caused by: org.eclipse.core.internal.resources.ResourceException: Resource '/rewrw/diagrams/rewrw.xmi' does not exist.
	at org.eclipse.core.internal.resources.Resource.checkExists(Resource.java:327)
	at org.eclipse.core.internal.resources.Resource.checkAccessible(Resource.java:201)
	at org.eclipse.core.internal.resources.File.getContents(File.java:291)
	at org.eclipse.core.internal.resources.File.getContents(File.java:282)
	at org.eclipse.emf.ecore.resource.impl.PlatformResourceURIHandlerImpl$WorkbenchHelper.createPlatformResourceInputStream(PlatformResourceURIHandlerImpl.java:208)
	at org.eclipse.emf.ecore.resource.impl.PlatformResourceURIHandlerImpl.createInputStream(PlatformResourceURIHandlerImpl.java:452)
	at org.eclipse.emf.ecore.resource.impl.ExtensibleURIConverterImpl.createInputStream(ExtensibleURIConverterImpl.java:350)
	at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1257)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:255)
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:270)
	... 35 more
Comment 6 Petya Sabeva CLA 2011-05-13 06:27:30 EDT
Created attachment 195576 [details]
Avoid deadlock

I wasn't able to reproduce the issue, but I suppose that this exception is logged because the project is closed before the editor and the diagram.xmi file couldn't be found. So with this patch everything should work fine, because using it the editor is closed in the PRE_CLOSED phase of the "close resource action"...
Comment 7 Petya Sabeva CLA 2011-05-13 06:28:00 EDT
Created attachment 195577 [details]
Patch for junit tests
Comment 8 Stefan Dimov CLA 2011-05-13 11:04:23 EDT
This patch has a little incompatibility with the patch in bug 345274. So I'll wait 'till the patch from 345274 is committed and then we'll change this one and propose it for PMC review.
Comment 9 Petya Sabeva CLA 2011-05-25 06:10:49 EDT
Created attachment 196529 [details]
Close JPA Editor before closing project
Comment 10 Stefan Dimov CLA 2011-05-25 10:16:26 EDT
I tried the fix and I was able to reproduce the deadlock:

1. Create JPA project
2. Create one entity in it
3. Visualize entity in the JPA Editor
4. Open the entity in the java editor
5. Make sure that the diagram editor is on top
6. Try to close the project

As a result the close operation will deadlock.

NOTE: The operation won't deadlock if the diagram is empty or if the diagram editor is not on top. I guess it has something to do with the project update and the order of editor closing
Comment 11 Neil Hauge CLA 2011-05-25 11:33:16 EDT
*** Bug 346891 has been marked as a duplicate of this bug. ***
Comment 12 Stefan Dimov CLA 2011-05-25 12:08:02 EDT
Created attachment 196568 [details]
patch

This one is good. I've just added some refinement ...
Comment 13 Stefan Dimov CLA 2011-05-25 12:20:59 EDT
I'm not sure if it's stop-ship defect, but it certanly is close. Deadlock of the UI thread is an ugly thing.

There is a workaround - close the diagram, before closing the project, but still - it's ugly and it has to be fixed ...

The fix was tested manually. One of the existing tests had to be fixed (there is an additional patch for it) in order all to pass successfully.

With this fix the editor is closed in the PRE_CLOSED phase of the "close resource action". I've reviewed the fix.

The risk is moderate.
Comment 14 David Williams CLA 2011-05-25 13:12:08 EDT
I'm ok with this for RC3 ... if Neil is. :) 

I just say that since does look like a fairly large, complicated change (from casual glance at patch) so would be good to get some extra eyes to review it. 

But, I agree its a bad enough problem to fix in RC3.
Comment 15 Neil Hauge CLA 2011-05-25 13:29:30 EDT
I just completed some testing.  The problem seems to be resolved with the latest patch and I haven't noticed any obvious regressions.  

Not sure why I hadn't noticed before, but it seems that the first time you create a diagram and add some entities you are unable to save it.  It seems this is not related to any recent patches as I can reproduce it in RC1 as well, so is a separate issue.  I'll open a separate bug for that.
Comment 16 Stefan Dimov CLA 2011-05-25 13:48:21 EDT
Committed and released - Hudson build job succeeded
Comment 17 Stefan Dimov CLA 2011-05-25 13:48:31 EDT
.
Comment 18 Jolene Moffitt CLA 2011-06-29 15:02:20 EDT
Verified in Build I-3.3.0RC4-20110603221533

Verified you can close a project when the diagram is open, has an entity listed in the diagram, or is on top and the focus in the editor.  See the link to view test steps for verification. http://wiki.eclipse.org/Dali_3.0_RC3