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

Bug 328761

Summary: Deadlock in text editor
Product: [Eclipse Project] Platform Reporter: Alain Lee <a-lee>
Component: TextAssignee: Platform-Text-Inbox <platform-text-inbox>
Status: RESOLVED NOT_ECLIPSE QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, nsand.dev, rakes123, remy.suen, thatnitind
Version: 3.6   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Alain Lee CLA 2010-10-26 14:48:23 EDT
Build Identifier: Helio

The Text Editor can go into deadlock if users are making changes while the initialization job in org.eclipse.ui.internal.texteditor.quickdiff.DocumentLineDiffer is still running.

See the following trace:
Thread [main] - BLOCKED
owns the lock object from SynchronizableDocument
wait for DocumentLineDiffer
at org.eclipse.ui.internal.texteditor.quickdiff.DocumentLineDiffer.documentChanged(DocumentLineDiffer.java:813)
at org.eclipse.jface.text.AbstractDocument.doFireDocumentChanged2(AbstractDocument.java:769)
at org.eclipse.jface.text.AbstractDocument.doFireDocumentChanged(AbstractDocument.java:736)
at org.eclipse.jface.text.AbstractDocument.doFireDocumentChanged(AbstractDocument.java:721)
at org.eclipse.jface.text.AbstractDocument.fireDocumentChanged(AbstractDocument.java:796)
at org.eclipse.jface.text.AbstractDocument.replace(AbstractDocument.java:1191)
at org.eclipse.core.internal.filebuffers.SynchronizableDocument.replace(SynchronizableDocument.java:195)
at org.eclipse.jface.text.AbstractDocument.replace(AbstractDocument.java:1210)
at org.eclipse.core.internal.filebuffers.SynchronizableDocument.replace(SynchronizableDocument.java:181)

|Thread [Worker-2] - BLOCKED
owns DocumentLineDiffer
wait for the lock object from SynchronizableDocument
at org.eclipse.jface.text.source.AnnotationMap.keySetIterator(AnnotationMap.java:82)
at org.eclipse.jface.text.source.AnnotationModel.getAnnotationIterator(AnnotationModel.java:783)
at org.eclipse.jface.text.source.AnnotationModel.getAnnotationIterator(AnnotationModel.java:758)
at org.eclipse.jface.text.source.AnnotationModel.getAnnotationIterator(AnnotationModel.java:690)
at com.ti.ccstudio.system.setup.ui.editors.MultiPageXMLEditor$1.modelChanged(MultiPageXMLEditor.java:178)
at org.eclipse.jface.text.source.AnnotationModel.fireModelChanged(AnnotationModel.java:614)
at org.eclipse.jface.text.source.AnnotationModel$InternalModelListener.modelChanged(AnnotationModel.java:261)
at org.eclipse.ui.internal.texteditor.quickdiff.DocumentLineDiffer.fireModelChanged(DocumentLineDiffer.java:1526)
at org.eclipse.ui.internal.texteditor.quickdiff.DocumentLineDiffer.fireModelChanged(DocumentLineDiffer.java:1509)
at org.eclipse.ui.internal.texteditor.quickdiff.DocumentLineDiffer$2.run(DocumentLineDiffer.java:545)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)




Reproducible: Sometimes

Steps to Reproduce:
We ran some automated testcases that make changes to the editor immediately after it is opened.
Comment 1 Remy Suen CLA 2010-10-26 14:52:16 EDT
(In reply to comment #0)
> com.ti.ccstudio.system.setup.ui.editors.MultiPageXMLEditor$1.modelChanged(MultiPageXMLEditor.java:178)

What kind of files do you have open? XML?
Comment 2 Alain Lee CLA 2010-10-26 15:10:05 EDT
(In reply to comment #1)
> (In reply to comment #0)
> > com.ti.ccstudio.system.setup.ui.editors.MultiPageXMLEditor$1.modelChanged(MultiPageXMLEditor.java:178)
> What kind of files do you have open? XML?

Yes
Comment 3 Dani Megert CLA 2010-10-27 02:31:08 EDT
Please attach the full stack trace and provide either steps or the test.

Which build ID?

Moving to WTP since it happens with the XML editor.
Comment 4 Alain Lee CLA 2010-10-27 11:13:48 EDT
(In reply to comment #3)
> Please attach the full stack trace and provide either steps or the test.
> Which build ID?
> Moving to WTP since it happens with the XML editor.

Version: 3.6.0
Build id: I20100312-1448

Actually, it is not the XML editor. We have our own MultiPageXMLEditor that extneds from AbstractFormEditor. It happens randomly in our automated tests when changes were made to the editor immediately after it was opened. We tried the following steps manually and was able to reproduce:
1. Put a breakpoint inside the Job at org.eclipse.ui.internal.texteditor.quickdiff.DocumentLineDiffer.initialize(). The job should be halted after it acquires the lock on DocumentLineDiffer.this.
2. Open our MultiPageXMLEditor to edit a file.
3. Make changes on the editor.
4. Now, the UI is frozen and the main thread is waiting for DocumentLineDiffer.
5. Resume the job in org.eclipse.ui.internal.texteditor.quickdiff.DocumentLineDiffer.initialize(). 
6. The UI was frozen forever.

We captured the following trace:

Thread [main] (Suspended)	
	owns: Object  (id=9270)	
		waited by: Thread [Worker-4] (Suspended)	
	waiting for: DocumentLineDiffer  (id=9259)	
		owned by: Thread [Worker-4] (Suspended)	
	DocumentLineDiffer.documentAboutToBeChanged(DocumentEvent) line: 746	
	SynchronizableDocument(AbstractDocument).fireDocumentAboutToBeChanged(DocumentEvent) line: 665	
	SynchronizableDocument(AbstractDocument).replace(int, int, String, long) line: 1182	
	SynchronizableDocument.replace(int, int, String, long) line: 195	
	SynchronizableDocument(AbstractDocument).replace(int, int, String) line: 1210	
	SynchronizableDocument.replace(int, int, String) line: 181	
	MultiPageXMLEditor.saveUndoInfo() line: 646	
	MultiPageXMLEditor.saveUndoInfo(String) line: 610	
	SetupPropertyListDetails.saveUndoInfo(String) line: 347	
	SetupPropertyListDetails.access$1(SetupPropertyListDetails, String) line: 345	
	SetupPropertyListDetails$PropertyDataProvider.setValue(Object, String) line: 112	
	SetupPropertyListDetails$PropertyDataProvider.setFlag(Object, boolean) line: 135	
	CheckBoxPropertyField$1.widgetSelected(SelectionEvent) line: 34	
	TypedListener.handleEvent(Event) line: 234	
	EventTable.sendEvent(Event) line: 84	
	Button(Widget).sendEvent(Event) line: 1053	
	Display.runDeferredEvents() line: 4066	
	Display.readAndDispatch() line: 3657	
	Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 2629	
	Workbench.runUI() line: 2593	
	Workbench.access$4(Workbench) line: 2427	
	Workbench$7.run() line: 670	
	Realm.runWithDefault(Realm, Runnable) line: 332	
	Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 663	
	PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149	
	CCSWorkbench(IDEApplication).start(IApplicationContext) line: 115	
	EclipseAppHandle.run(Object) line: 196	
	EclipseAppLauncher.runApplication(Object) line: 110	
	EclipseAppLauncher.start(Object) line: 79	
	EclipseStarter.run(Object) line: 369	
	EclipseStarter.run(String[], Runnable) line: 179	
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39	
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25	
	Method.invoke(Object, Object...) line: 585	
	Main.invokeFramework(String[], URL[]) line: 619	
	Main.basicRun(String[]) line: 574	
	Main.run(String[]) line: 1407	
	Main.main(String[]) line: 1383	

Thread [Worker-4] (Suspended)	
	owns: DocumentLineDiffer  (id=9259)	
		waited by: Thread [main] (Suspended)	
	waiting for: Object  (id=9270)	
		owned by: Thread [main] (Suspended)	
	AnnotationMap.keySetIterator() line: 82	
	AnnotationModel.getAnnotationIterator(boolean) line: 783	
	AnnotationModel.getAnnotationIterator(boolean, boolean) line: 758	
	AnnotationModel.getAnnotationIterator() line: 690	
	MultiPageXMLEditor$1.modelChanged(IAnnotationModel) line: 178	
	AnnotationModel.fireModelChanged(AnnotationModelEvent) line: 614	
	AnnotationModel$InternalModelListener.modelChanged(AnnotationModelEvent) line: 261	
	DocumentLineDiffer.fireModelChanged(AnnotationModelEvent) line: 1526	
	DocumentLineDiffer.fireModelChanged() line: 1509	
	DocumentLineDiffer$2.run(IProgressMonitor) line: 545	
	Worker.run() line: 54	

(In reply to comment #3)
> Please attach the full stack trace and provide either steps or the test.
> Which build ID?
> Moving to WTP since it happens with the XML editor.
Comment 5 Alain Lee CLA 2010-10-27 11:15:33 EDT
I meant MultiPageXMLEditor extends from FormEditor.

(In reply to comment #4)
> (In reply to comment #3)
> > Please attach the full stack trace and provide either steps or the test.
> > Which build ID?
> > Moving to WTP since it happens with the XML editor.
> Version: 3.6.0
> Build id: I20100312-1448
> Actually, it is not the XML editor. We have our own MultiPageXMLEditor that
> extneds from AbstractFormEditor. It happens randomly in our automated tests
> when changes were made to the editor immediately after it was opened. We tried
> the following steps manually and was able to reproduce:
> 1. Put a breakpoint inside the Job at
> org.eclipse.ui.internal.texteditor.quickdiff.DocumentLineDiffer.initialize().
> The job should be halted after it acquires the lock on DocumentLineDiffer.this.
> 2. Open our MultiPageXMLEditor to edit a file.
> 3. Make changes on the editor.
> 4. Now, the UI is frozen and the main thread is waiting for DocumentLineDiffer.
> 5. Resume the job in
> org.eclipse.ui.internal.texteditor.quickdiff.DocumentLineDiffer.initialize(). 
> 6. The UI was frozen forever.
> We captured the following trace:
> Thread [main] (Suspended)    
>     owns: Object  (id=9270)    
>         waited by: Thread [Worker-4] (Suspended)    
>     waiting for: DocumentLineDiffer  (id=9259)    
>         owned by: Thread [Worker-4] (Suspended)    
>     DocumentLineDiffer.documentAboutToBeChanged(DocumentEvent) line: 746    
>    
> SynchronizableDocument(AbstractDocument).fireDocumentAboutToBeChanged(DocumentEvent)
> line: 665    
>     SynchronizableDocument(AbstractDocument).replace(int, int, String, long)
> line: 1182    
>     SynchronizableDocument.replace(int, int, String, long) line: 195    
>     SynchronizableDocument(AbstractDocument).replace(int, int, String) line:
> 1210    
>     SynchronizableDocument.replace(int, int, String) line: 181    
>     MultiPageXMLEditor.saveUndoInfo() line: 646    
>     MultiPageXMLEditor.saveUndoInfo(String) line: 610    
>     SetupPropertyListDetails.saveUndoInfo(String) line: 347    
>     SetupPropertyListDetails.access$1(SetupPropertyListDetails, String) line:
> 345    
>     SetupPropertyListDetails$PropertyDataProvider.setValue(Object, String)
> line: 112    
>     SetupPropertyListDetails$PropertyDataProvider.setFlag(Object, boolean)
> line: 135    
>     CheckBoxPropertyField$1.widgetSelected(SelectionEvent) line: 34    
>     TypedListener.handleEvent(Event) line: 234    
>     EventTable.sendEvent(Event) line: 84    
>     Button(Widget).sendEvent(Event) line: 1053    
>     Display.runDeferredEvents() line: 4066    
>     Display.readAndDispatch() line: 3657    
>     Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 2629    
>     Workbench.runUI() line: 2593    
>     Workbench.access$4(Workbench) line: 2427    
>     Workbench$7.run() line: 670    
>     Realm.runWithDefault(Realm, Runnable) line: 332    
>     Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 663    
>     PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 149    
>     CCSWorkbench(IDEApplication).start(IApplicationContext) line: 115    
>     EclipseAppHandle.run(Object) line: 196    
>     EclipseAppLauncher.runApplication(Object) line: 110    
>     EclipseAppLauncher.start(Object) line: 79    
>     EclipseStarter.run(Object) line: 369    
>     EclipseStarter.run(String[], Runnable) line: 179    
>     NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not
> available [native method]    
>     NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39    
>     DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25    
>     Method.invoke(Object, Object...) line: 585    
>     Main.invokeFramework(String[], URL[]) line: 619    
>     Main.basicRun(String[]) line: 574    
>     Main.run(String[]) line: 1407    
>     Main.main(String[]) line: 1383    
> Thread [Worker-4] (Suspended)    
>     owns: DocumentLineDiffer  (id=9259)    
>         waited by: Thread [main] (Suspended)    
>     waiting for: Object  (id=9270)    
>         owned by: Thread [main] (Suspended)    
>     AnnotationMap.keySetIterator() line: 82    
>     AnnotationModel.getAnnotationIterator(boolean) line: 783    
>     AnnotationModel.getAnnotationIterator(boolean, boolean) line: 758    
>     AnnotationModel.getAnnotationIterator() line: 690    
>     MultiPageXMLEditor$1.modelChanged(IAnnotationModel) line: 178    
>     AnnotationModel.fireModelChanged(AnnotationModelEvent) line: 614    
>     AnnotationModel$InternalModelListener.modelChanged(AnnotationModelEvent)
> line: 261    
>     DocumentLineDiffer.fireModelChanged(AnnotationModelEvent) line: 1526    
>     DocumentLineDiffer.fireModelChanged() line: 1509    
>     DocumentLineDiffer$2.run(IProgressMonitor) line: 545    
>     Worker.run() line: 54    
> (In reply to comment #3)
> > Please attach the full stack trace and provide either steps or the test.
> > Which build ID?
> > Moving to WTP since it happens with the XML editor.
Comment 6 Rakesh CLA 2010-10-29 05:51:45 EDT
WTP is not involved here , since it is not wtp's editor.It looks like a synchronization issue between SynchronizableDocument ,AnnotationMap and DocumentLineDiffer.
Comment 7 Dani Megert CLA 2010-10-29 06:18:45 EDT
(In reply to comment #6)
> WTP is not involved here , since it is not wtp's editor.It looks like a
Please read comment 5: I meant MultiPageXMLEditor extends from FormEditor.
Comment 8 Nick Sandonato CLA 2010-10-29 10:28:35 EDT
(In reply to comment #7)
> (In reply to comment #6)
> > WTP is not involved here , since it is not wtp's editor.It looks like a
> Please read comment 5: I meant MultiPageXMLEditor extends from FormEditor.

This MultiPageXMLEditor is com.ti.ccstudio.system.setup.ui.editors.MultiPageXMLEditor. As far as I can tell from the stacktraces, nothing from SSE is involved. I think this might be better suited for Text.
Comment 9 Dani Megert CLA 2010-10-29 11:20:08 EDT
> com.ti.ccstudio.system.setup.ui.editors.MultiPageXMLEditor. As far as I can
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Please file the bug there.
Comment 10 Alain Lee CLA 2010-10-29 11:50:19 EDT
(In reply to comment #9)
> > com.ti.ccstudio.system.setup.ui.editors.MultiPageXMLEditor. As far as I can
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Please file the bug there.

There must be a synchronization issue between SynchronizableDocument, AnnotationMap and
DocumentLineDiffer. MultiPageXMLEditor only called SynchronizableDocument.replace() and the UI thread got frozen forever. MultiPageXMLEditor has not know whether the initialization job in DocumentLineDiffer is completed so it cannot delay the call to SynchronizableDocument.replace(). I can't find a better way to put a fix in MultiPageXMLEditor.
Comment 11 Dani Megert CLA 2010-11-01 03:58:39 EDT
The indicated build in comment 0 (Helio) does not match with the build ID given in comment 4:

>Version: 3.6.0
>Build id: I20100312-1448

Please retry with 3.6.1 and if the problem can still be reproduced, attach the steps and/or test case here. Otherwise there's nothing we can do.
Comment 12 Alain Lee CLA 2010-11-01 10:09:06 EDT
(In reply to comment #11)
> The indicated build in comment 0 (Helio) does not match with the build ID given
> in comment 4:
> >Version: 3.6.0
> >Build id: I20100312-1448
> Please retry with 3.6.1 and if the problem can still be reproduced, attach the
> steps and/or test case here. Otherwise there's nothing we can do.


As I said, this only happens in our automated tests when all usrs actions were performed very fast. I can't find an easy way to reproduce it manually other than the steps I mentioned previously. It is very unlikely that this situation will happen in our customers sites. We can workaround it in our automated tests.
Comment 13 Dani Megert CLA 2010-11-01 10:10:47 EDT
> As I said, this only happens in our automated tests when all usrs actions were
> performed very fast.
Did you try with 3.6.1?