Bug 188340 - Pasted type not shown in package explorer
Summary: Pasted type not shown in package explorer
Status: RESOLVED DUPLICATE of bug 189722
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-05-22 11:21 EDT by Benno Baumgartner CLA
Modified: 2007-06-20 10:19 EDT (History)
5 users (show)

See Also:


Attachments
Possible workaround (3.04 KB, patch)
2007-05-29 13:22 EDT, Jerome Lanneluc CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benno Baumgartner CLA 2007-05-22 11:21:58 EDT
I20070517-1700

Given new workspace
1. Past:

package b;
public class E01{}

into empty package explorer
2. In PE select E01
3. Past

package b;
public class E02{}

Is:
 E02 does not appear in PE
Should:
 appear and be selected
Comment 1 Martin Aeschlimann CLA 2007-05-24 10:56:31 EDT
Delta after step 1:

Java Model[*]: {CHILDREN}
	_pasted_code_[+]: {}
[Working copy] E01.java[*]: {AST AFFECTED}

Delta after step 3:

Java Model[*]: {CHILDREN}
	_pasted_code_[*]: {CHILDREN}
		src[*]: {CHILDREN}
			b[+]: {}
[Working copy] E02.java[*]: {AST AFFECTED}


The problem seems to be that 'b' is marked as addition, but it already exists at time and the package explorer is skipping that delta.
The delta should mark 'b' as changed and 'E02' as added.

Moving to jdt.core
Comment 2 Jerome Lanneluc CLA 2007-05-25 09:56:12 EDT
Cannot reproduce. After step 3, I get:
FIRING POST_CHANGE Delta [Thread[main,6,main]]:
Java Model[*]: {CHILDREN}
	_pasted_code_[*]: {CHILDREN}
		src[*]: {CHILDREN}
			b[*]: {CHILDREN}
				[Working copy] E02.java[+]: {}

and the PE correctly shows E02.
Comment 3 Martin Aeschlimann CLA 2007-05-25 10:05:46 EDT
It only works with a fresh workspace and exactly the provided steps.
I guess with your delta you can also not reproduce the initial bug.
Comment 4 Jerome Lanneluc CLA 2007-05-25 10:12:29 EDT
Yep, I started with a fresh workspace and followed the steps given in comment 0
Comment 5 Jerome Lanneluc CLA 2007-05-25 10:43:56 EDT
Note with 3.2, you had to create a Java project before step 1. After creating this Java project, and following the given steps, E02 appeared in the PE.
Comment 6 Jerome Lanneluc CLA 2007-05-28 07:25:03 EDT
I finally was able to reproduce the problem on a slow machine.
On step 1, I'm seeing the project being created in the 'main' thread, but the corresponding resource delta being reported in a 'Worker-2' thread. This is what's causing the JDT/Core delta processor to fail.

Thread [Worker-2] (Suspended (breakpoint at line 368 in DeltaProcessingState))	
	DeltaProcessingState.resourceChanged(IResourceChangeEvent) line: 368	
	NotificationManager$2.run() line: 282	
	SafeRunner.run(ISafeRunnable) line: 37	
	NotificationManager.notify(ResourceChangeListenerList$ListenerEntry[], IResourceChangeEvent, boolean) line: 276	
	NotificationManager.broadcastChanges(ElementTree, ResourceChangeEvent, boolean) line: 148	
	Workspace.broadcastPostChange() line: 311	
	Workspace.endOperation(ISchedulingRule, boolean, IProgressMonitor) line: 1018	
	Workspace.run(IWorkspaceRunnable, ISchedulingRule, int, IProgressMonitor) line: 1806	
	NotificationManager$NotifyJob.run(IProgressMonitor) line: 39	
	Worker.run() line: 55	

John, can't we assume that the delta is going to be reported in the same thread that modified the resource any longer ? Or would that be a bug in Platform/Resources ?
Comment 7 John Arthorne CLA 2007-05-28 10:49:35 EDT
> John, can't we assume that the delta is going to be reported in the same 
> thread that modified the resource any longer ?

It has been like this since Eclipse 3.0. When two threads are modifying the workspace concurrently, a POST_CHANGE event could occur in either thread. That delta will contain all changes since the last POST_CHANGE event, regardless of what thread the changes occurred in.

FWIW, here is what the resource delta looked like after step 1:

/[*]: {}
/_pasted_code_[+]: {OPEN}
/_pasted_code_/.classpath[+]: {}
/_pasted_code_/.project[+]: {}
/_pasted_code_/.settings[+]: {}
/_pasted_code_/.settings/org.eclipse.jdt.core.prefs[+]: {}
/_pasted_code_/src[+]: {}
/_pasted_code_/src/b[+]: {}
/_pasted_code_/src/b/E01.java[+]: {}

And here is the resource delta after step 3:

/[*]: {}
/_pasted_code_[*]: {}
/_pasted_code_/src[*]: {}
/_pasted_code_/src/b[*]: {}
/_pasted_code_/src/b/E02.java[+]: {}

These deltas look correct.
Comment 8 Jerome Lanneluc CLA 2007-05-28 11:38:52 EDT
Indeed the delta looks correct, but it is notified in the NotificationManager thread (I'm not sure what this notification manager is), it is NOT notified in the 'main' thread where the change occurred. 

Looking at the doc, I don't see anything that says that a resource delta could be notified in a different thread than the thread where the modification occurred.
Comment 9 John Arthorne CLA 2007-05-28 13:57:45 EDT
There is also nothing in the doc that says events do occur in the same thread as the modification <g>. I seem to recall a long bugzilla discussion about this in the past, but I can't find it now. There is a trade-off here: if we guaranteed that events occurred in the same thread, then we would not be able to guarantee that events are received in the same order in which the changes occurred. It would also be expensive to track the thread that each change occurred in.
Comment 10 Philipe Mulet CLA 2007-05-29 05:28:54 EDT
I wasn't aware either of notifications being able to occur in a different thread, at least for post-change (pre/post-build may occur elsewhere due to background autobuild).
Comment 11 Jerome Lanneluc CLA 2007-05-29 13:11:25 EDT
I wasn't aware of this either. This is scary since we always assumed that the resource event would occur in the same thread as where the modification occurred. I suspect we are not the only ones to make this assumption.

I entered bug 189722 against JDT/Core to remove this assumption. Of course this is too big of a change for RC3, and it will have to wait until after 3.3.
Comment 12 Jerome Lanneluc CLA 2007-05-29 13:22:09 EDT
Created attachment 69095 [details]
Possible workaround

The workaround consists in ensuring that posted Java deltas are fired after the batch operation has finished
Comment 13 John Arthorne CLA 2007-05-29 15:46:58 EDT
I'm surprised this hasn't bitten you earlier, since it has been like this for three years. I expect it to be quite common for the notifications to happen in a different thread. This happens when there is an intermediate resource change event during a long operation, or when there are multiple resource changes happening concurrently in different threads (resource change will be broadcast at the end of the operation that finishes last).
Comment 14 Philipe Mulet CLA 2007-05-30 07:23:21 EDT
Our delta processing has also been relying on it for the same amount of time (years)... scary indeed.
Comment 15 Philipe Mulet CLA 2007-05-30 07:28:32 EDT
Re: patch from Jerome
Comment 16 Philipe Mulet CLA 2007-05-30 07:29:37 EDT
Re: patch from Jerome

Isn't there a risk that a client may get 2 deltas for the same Java model operation now in 2 different threads ? (one for the Java model delta, one for the converted rsc delta).
Comment 17 Martin Aeschlimann CLA 2007-06-05 08:52:22 EDT
*** Bug 190858 has been marked as a duplicate of this bug. ***
Comment 18 Jerome Lanneluc CLA 2007-06-20 10:06:50 EDT
DeltaProcessor needs to be rewritten to not assume that the resource delta is sent in the same thread as where the resource was modified.
Comment 19 Jerome Lanneluc CLA 2007-06-20 10:12:31 EDT
*** Bug 186858 has been marked as a duplicate of this bug. ***
Comment 20 Jerome Lanneluc CLA 2007-06-20 10:19:21 EDT

*** This bug has been marked as a duplicate of bug 189722 ***