Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 275286 - [compare] createStructure is called three times for both sides when opening compare editor
Summary: [compare] createStructure is called three times for both sides when opening c...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.5 RC1   Edit
Assignee: Dani Megert CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 275289 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-05-07 07:31 EDT by Tomasz Zarna CLA
Modified: 2009-05-15 06:12 EDT (History)
1 user (show)

See Also:
tomasz.zarna: review+


Attachments
Patch v01 (953 bytes, patch)
2009-05-08 05:05 EDT, Tomasz Zarna CLA
no flags Details | Diff
mylyn/context/zip (11.72 KB, application/octet-stream)
2009-05-08 05:05 EDT, Tomasz Zarna CLA
no flags Details
Fix (2.46 KB, patch)
2009-05-11 09:12 EDT, Dani Megert CLA
no flags Details | Diff
Fix 2 (2.15 KB, patch)
2009-05-11 10:02 EDT, 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 Tomasz Zarna CLA 2009-05-07 07:31:13 EDT
3.5M7

Select two Java files in PE and do Compare With > Each Other. org.eclipse.compare.structuremergeviewer.StructureCreator.createStructure(Object, IProgressMonitor) is called 3 times for each side resulting in creating AST 6 times total. 

- first, when setting input on structure pane
- second, when updating content of content pane
- third,  called by JavaReconciler

Individual stacks will follow.

The issue is similar to what Dani observed in bug 262557, comment 7, bullet 2.
Comment 1 Tomasz Zarna CLA 2009-05-07 07:31:46 EDT
Thread [main] (Suspended)	
	ASTParser.newParser(int) line: 118	
	JavaStructureCreator.createStructureComparator(Object, char[], IDocument, ISharedDocumentAdapter, IProgressMonitor) line: 289	
	JavaStructureCreator.createStructureComparator(Object, IDocument, ISharedDocumentAdapter, IProgressMonitor) line: 253	
	JavaStructureCreator(StructureCreator).internalCreateStructure(Object, IProgressMonitor) line: 102	
	StructureCreator.access$0(StructureCreator, Object, IProgressMonitor) line: 90	
	StructureCreator$1.run() line: 80	
	BusyIndicator.showWhile(Display, Runnable) line: 70	
	Utilities.runInUIThread(Runnable) line: 775	
	JavaStructureCreator(StructureCreator).createStructure(Object, IProgressMonitor) line: 83	

Thread [main] (Suspended (breakpoint at line 77 in StructureCreator))	
	JavaStructureCreator(StructureCreator).createStructure(Object, IProgressMonitor) line: 77	
	StructureDiffViewer$StructureInfo.createStructure(IProgressMonitor) line: 155	
	StructureDiffViewer$StructureInfo.refresh(IProgressMonitor) line: 133	
	StructureDiffViewer$StructureInfo.setInput(ITypedElement, boolean, IProgressMonitor) line: 104	
	JavaStructureDiffViewer(StructureDiffViewer).compareInputChanged(ICompareInput, boolean, IProgressMonitor) line: 347	
	StructureDiffViewer$2.run(IProgressMonitor) line: 74	
	StructureDiffViewer$6.run() line: 322	
	BusyIndicator.showWhile(Display, Runnable) line: 70	
	JavaStructureDiffViewer(StructureDiffViewer).compareInputChanged(ICompareInput, boolean) line: 319	
	JavaStructureDiffViewer(StructureDiffViewer).compareInputChanged(ICompareInput) line: 307	
	JavaStructureDiffViewer.compareInputChanged(ICompareInput) line: 160	
	JavaStructureDiffViewer(StructureDiffViewer).inputChanged(Object, Object) line: 278	
	JavaStructureDiffViewer(ContentViewer).setInput(Object) line: 274	
	JavaStructureDiffViewer(StructuredViewer).setInput(Object) line: 1634	
	CompareEditorInput$9(CompareViewerSwitchingPane).setInput(Object) line: 270	
	CompareEditorInput$9(CompareStructureViewerSwitchingPane).setInput(Object) line: 132	
=>	SaveablesCompareEditorInput(CompareEditorInput).feedInput() line: 718	
	SaveablesCompareEditorInput(CompareEditorInput).createContents(Composite) line: 545	
	CompareEditor.createCompareControl() line: 449	
	CompareEditor.access$6(CompareEditor) line: 416	
	CompareEditor$3.run() line: 372
	...
Comment 2 Tomasz Zarna CLA 2009-05-07 07:33:23 EDT
Thread [main] (Suspended)
	ASTParser.newParser(int) line: 118
	JavaStructureCreator.createStructureComparator(Object, char[], IDocument, ISharedDocumentAdapter, IProgressMonitor) line: 289
	JavaStructureCreator.createStructureComparator(Object, IDocument, ISharedDocumentAdapter, IProgressMonitor) line: 253
	JavaStructureCreator(StructureCreator).internalCreateStructure(Object, IProgressMonitor) line: 102
	StructureCreator.access$0(StructureCreator, Object, IProgressMonitor) line: 90
	StructureCreator$1.run() line: 80
	BusyIndicator.showWhile(Display, Runnable) line: 70
	Utilities.runInUIThread(Runnable) line: 775
	JavaStructureCreator(StructureCreator).createStructure(Object, IProgressMonitor) line: 83	

Thread [Worker-7] (Suspended (breakpoint at line 77 in StructureCreator))	
	JavaStructureCreator(StructureCreator).createStructure(Object, IProgressMonitor) line: 77	
	StructureDiffViewer$StructureInfo.createStructure(IProgressMonitor) line: 155	
	StructureDiffViewer$StructureInfo.refresh(IProgressMonitor) line: 133	
	StructureDiffViewer$3.run(IProgressMonitor) line: 89
	Worker.performNextTask(SubMonitor) line: 116	
	Worker.run(IProgressMonitor) line: 63	
	CompareEditor$1(WorkerJob).run(IProgressMonitor) line: 30	
	Worker.run() line: 55	

Thread [main] (Suspended (breakpoint at line 171 in StructureDiffViewer$StructureInfo))	
	StructureDiffViewer$StructureInfo.getRefreshTask() line: 171	
	JavaStructureDiffViewer(StructureDiffViewer).contentChanged(IContentChangeNotifier) line: 401	
	JavaStructureDiffViewer.elementChanged(ElementChangedEvent) line: 258	
	DeltaProcessor$3.run() line: 1557	
	SafeRunner.run(ISafeRunnable) line: 42	
	DeltaProcessor.notifyListeners(IJavaElementDelta, int, IElementChangedListener[], int[], int) line: 1547	
	DeltaProcessor.firePostChangeDelta(IJavaElementDelta, IElementChangedListener[], int[], int) line: 1381	
	DeltaProcessor.fire(IJavaElementDelta, int) line: 1357	
	BecomeWorkingCopyOperation(JavaModelOperation).run(IProgressMonitor) line: 769	
	BecomeWorkingCopyOperation(JavaModelOperation).runOperation(IProgressMonitor) line: 788	
	CompilationUnit.becomeWorkingCopy(IProblemRequestor, IProgressMonitor) line: 100	
	CompilationUnitDocumentProvider.createFileInfo(Object) line: 983	
	CompilationUnitDocumentProvider(TextFileDocumentProvider).connect(Object) line: 478	
	CompilationUnitDocumentProvider.connect(Object) line: 1198	
	JavaMergeViewer$CompilationUnitEditorAdapter(AbstractTextEditor).doSetInput(IEditorInput) line: 4100	
	JavaMergeViewer$CompilationUnitEditorAdapter(StatusTextEditor).doSetInput(IEditorInput) line: 203	
	JavaMergeViewer$CompilationUnitEditorAdapter(AbstractDecoratedTextEditor).doSetInput(IEditorInput) line: 1330	
	JavaMergeViewer$CompilationUnitEditorAdapter(JavaEditor).internalDoSetInput(IEditorInput) line: 2552	
	JavaMergeViewer$CompilationUnitEditorAdapter(JavaEditor).doSetInput(IEditorInput) line: 2539	
	JavaMergeViewer$CompilationUnitEditorAdapter(CompilationUnitEditor).doSetInput(IEditorInput) line: 1371	
	JavaMergeViewer$CompilationUnitEditorAdapter.doSetInput(IEditorInput) line: 553	
	AbstractTextEditor$19.run(IProgressMonitor) line: 3081	
	ModalContext.runInCurrentThread(IRunnableWithProgress, IProgressMonitor) line: 464	
	ModalContext.run(IRunnableWithProgress, boolean, IProgressMonitor, Display) line: 372	
	ApplicationWindow$1.run() line: 759	
	BusyIndicator.showWhile(Display, Runnable) line: 70	
	WorkbenchWindow(ApplicationWindow).run(boolean, boolean, IRunnableWithProgress) line: 756	
	WorkbenchWindow.run(boolean, boolean, IRunnableWithProgress) line: 2576	
	JavaMergeViewer$CompilationUnitEditorAdapter(AbstractTextEditor).internalInit(IWorkbenchWindow, IEditorSite, IEditorInput) line: 3099	
	JavaMergeViewer$CompilationUnitEditorAdapter(AbstractTextEditor).init(IEditorSite, IEditorInput) line: 3126	
	JavaMergeViewer.getSourceViewerConfiguration(SourceViewer, IEditorInput) line: 268	
	JavaMergeViewer.configureTextViewer(TextViewer) line: 213	
	JavaMergeViewer(TextMergeViewer).configureSourceViewer(SourceViewer, boolean) line: 2890	
	JavaMergeViewer(TextMergeViewer).updateContent(Object, Object, Object) line: 2843	
	JavaMergeViewer(ContentMergeViewer).internalRefresh(Object) line: 737	
	JavaMergeViewer(ContentMergeViewer).inputChanged(Object, Object) line: 637	
	JavaMergeViewer(ContentViewer).setInput(Object) line: 274	
	JavaMergeViewer.setInput(Object) line: 153	
	CompareContentViewerSwitchingPane(CompareViewerSwitchingPane).setInput(Object) line: 270	
	CompareContentViewerSwitchingPane.setInput(Object) line: 132	
	SaveablesCompareEditorInput(CompareEditorInput).internalSetContentPaneInput(Object) line: 812	
	CompareEditorInput.access$7(CompareEditorInput, Object) line: 810	
	CompareEditorInput$10.run() line: 750	
	BusyIndicator.showWhile(Display, Runnable) line: 70	
	SaveablesCompareEditorInput(CompareEditorInput).feed1(ISelection) line: 744	
=>	SaveablesCompareEditorInput(CompareEditorInput).feedInput() line: 722	
	SaveablesCompareEditorInput(CompareEditorInput).createContents(Composite) line: 545	
	CompareEditor.createCompareControl() line: 449	
	CompareEditor.access$6(CompareEditor) line: 416	
	CompareEditor$3.run() line: 372	
	...
Comment 3 Tomasz Zarna CLA 2009-05-07 07:33:40 EDT
Thread [main] (Suspended)	
	ASTParser.newParser(int) line: 118	
	JavaStructureCreator.createStructureComparator(Object, char[], IDocument, ISharedDocumentAdapter, IProgressMonitor) line: 289	
	JavaStructureCreator.createStructureComparator(Object, IDocument, ISharedDocumentAdapter, IProgressMonitor) line: 253	
	JavaStructureCreator(StructureCreator).internalCreateStructure(Object, IProgressMonitor) line: 102	
	StructureCreator.access$0(StructureCreator, Object, IProgressMonitor) line: 90	
	StructureCreator$1.run() line: 80	
	BusyIndicator.showWhile(Display, Runnable) line: 70	
	Utilities.runInUIThread(Runnable) line: 775	
	JavaStructureCreator(StructureCreator).createStructure(Object, IProgressMonitor) line: 83	

Thread [Worker-7] (Suspended (breakpoint at line 77 in StructureCreator))	
	JavaStructureCreator(StructureCreator).createStructure(Object, IProgressMonitor) line: 77	
	StructureDiffViewer$StructureInfo.createStructure(IProgressMonitor) line: 155	
	StructureDiffViewer$StructureInfo.refresh(IProgressMonitor) line: 133	
	StructureDiffViewer$3.run(IProgressMonitor) line: 89	
	Worker.performNextTask(SubMonitor) line: 116	
	Worker.run(IProgressMonitor) line: 63	
	CompareEditor$1(WorkerJob).run(IProgressMonitor) line: 30	
	Worker.run() line: 55	

Daemon Thread [org.eclipse.jdt.internal.ui.text.JavaReconciler] (Suspended (breakpoint at line 171 in StructureDiffViewer$StructureInfo))	
	StructureDiffViewer$StructureInfo.getRefreshTask() line: 171	
	JavaStructureDiffViewer(StructureDiffViewer).contentChanged(IContentChangeNotifier) line: 399	
	JavaStructureDiffViewer.elementChanged(ElementChangedEvent) line: 258	
	DeltaProcessor$3.run() line: 1557	
	SafeRunner.run(ISafeRunnable) line: 42	
	DeltaProcessor.notifyListeners(IJavaElementDelta, int, IElementChangedListener[], int[], int) line: 1547	
	DeltaProcessor.fireReconcileDelta(IElementChangedListener[], int[], int) line: 1399	
	DeltaProcessor.fire(IJavaElementDelta, int) line: 1358	
	ReconcileWorkingCopyOperation(JavaModelOperation).run(IProgressMonitor) line: 769	
	ReconcileWorkingCopyOperation(JavaModelOperation).runOperation(IProgressMonitor) line: 788	
	CompilationUnit.reconcile(int, int, WorkingCopyOwner, IProgressMonitor) line: 1242	
	JavaReconcilingStrategy.reconcile(ICompilationUnit, boolean) line: 126	
	JavaReconcilingStrategy.access$0(JavaReconcilingStrategy, ICompilationUnit, boolean) line: 108	
	JavaReconcilingStrategy$1.run() line: 89	
	SafeRunner.run(ISafeRunnable) line: 42	
	JavaReconcilingStrategy.reconcile(boolean) line: 87	
	JavaReconcilingStrategy.initialReconcile() line: 178	
	JavaCompositeReconcilingStrategy(CompositeReconcilingStrategy).initialReconcile() line: 114	
	JavaCompositeReconcilingStrategy.initialReconcile() line: 133	
	JavaReconciler(MonoReconciler).initialProcess() line: 105	
	JavaReconciler.initialProcess() line: 398	
	AbstractReconciler$BackgroundThread.run() line: 173	
Comment 4 Tomasz Zarna CLA 2009-05-08 04:40:57 EDT
Having createStructure called multiple times for the same element may cause OperationCanceledException to be thrown (see bug 262557 where OCE is thrown on save).
Comment 5 Tomasz Zarna CLA 2009-05-08 05:05:50 EDT
Created attachment 134945 [details]
Patch v01

From my understaing of how IJavaElementDelta works, in order to tests whether a delta represents a content change it need to be IJavaElementDelta.CHANGED kind *and* one of the flags must be IJavaElementDelta.F_CONTENT. CHANGED kind is not enough as it may, for instance represent, opening an element.

Dani, what do you think? The change is 100% on JDT side.
Comment 6 Tomasz Zarna CLA 2009-05-08 05:05:56 EDT
Created attachment 134946 [details]
mylyn/context/zip
Comment 7 Tomasz Zarna CLA 2009-05-08 05:42:49 EDT
Dani, you're an expert here, do you think that reacting to an event of IJavaElementDelta.CHANGED kind and IJavaElementDelta.F_CONTENT flag is enough? Or should we also consider IJavaElementDelta.F_AST_AFFECTED flags too? From how I see it the second is a consequence of the first, but I may be wrong.
Comment 8 Dani Megert CLA 2009-05-11 09:11:37 EDT
The patch goes into the right direction but we can be more aggressive:
1) we only need to update on structure change. We can ignore simple changes to
   the content (e.g. method body) because we don't show error ticks
2) we should also ignore create and commit working copy deltas

The attached patch fixes this. Tomasz, please review.

Comment 9 Dani Megert CLA 2009-05-11 09:12:13 EDT
Created attachment 135131 [details]
Fix
Comment 10 Tomasz Zarna CLA 2009-05-11 09:29:04 EDT
I'm fine with 2), but we need to keep an eye on content changes in order to fix bug 260865, so I don't feel comfortable with 1).
Comment 11 Tomasz Zarna CLA 2009-05-11 09:36:30 EDT
... and bug 165434.
Comment 12 Dani Megert CLA 2009-05-11 10:02:10 EDT
Oh, right, forgot about those, so we need to handle content change as well. In that case your proposed fix is still wrong because you can have changes in lower level elements but no change to the content (e.g. rename of a method). What we really want to ignore are deltas with a new AST but no real changes to the CU itself.
Comment 13 Dani Megert CLA 2009-05-11 10:02:31 EDT
Created attachment 135138 [details]
Fix 2
Comment 14 Tomasz Zarna CLA 2009-05-11 11:10:31 EDT
Looks good to me, thanks Dani. Shouldn't we move the bug to JDT/UI and change the assignee, you prepared the patch, not me.
Comment 15 Tomasz Zarna CLA 2009-05-11 11:21:08 EDT
*** Bug 275289 has been marked as a duplicate of this bug. ***
Comment 16 Dani Megert CLA 2009-05-11 11:23:05 EDT
Fixed in HEAD.
Available in builds >= I20090511-2000.
Comment 17 Dani Megert CLA 2009-05-15 06:12:16 EDT
Verified in I20090514-2000 with breakpoints.