Bug 45721 - Getting wrong deltas
Summary: Getting wrong deltas
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.0 M7   Edit
Assignee: Jerome Lanneluc CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-29 07:13 EST by Dirk Baeumer CLA
Modified: 2004-01-06 10:51 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dirk Baeumer CLA 2003-10-29 07:13:45 EST
N20031029, but was able to reproduce with JDT/Core v_379a as well.

What I see is that I get the delta of adding a field to a type is sent out 
when manipulating the type a second time. Here are steps to reproduce:

- set two breakpoints in AllTypesCacheTest:testNewElementCreation (please make
  sure that the suite method of the test either executes all tests or that
  the testNewElementCreation method is passed to the constructor. Otherwise
  you will never execute the test).
  first at line(210): type.createField("public int fCount;", null, true, null);
  second at line(212): res1.clear();

- run the test case under debugger

- when hitting the first breakpoint set a break point in
  TypeCacheDeltaListener#elementChanged which is a inner type of the
  AllTypesCache

- resume. The delta sent out by adding the field is:

  org.eclipse.jdt.core.ElementChangedEvent[source=Java Model[*]: {CHILDREN}
	TestProject2[*]: {CHILDREN}
		src[*]: {CHILDREN}
			<default>[*]: {CHILDREN}
				A.java[*]: {CONTENT}]

- resume

- now "slowly" step over including the statment type.createType("public class 
  AInner {}", null, true, null); 
  This seems to be important. Sometime when directly resuming the second delta
  contained the newly added type and field.

- the break point in the element change listener is hit again

- the delta sent out by adding the type is

org.eclipse.jdt.core.ElementChangedEvent[source=Java Model[*]: {CHILDREN}
	TestProject2[*]: {CHILDREN}
		src[*]: {CHILDREN}
			<default>[*]: {CHILDREN}
				A.java[*]: {CHILDREN | FINE GRAINED}
					A[*]: {CHILDREN | FINE GRAINED}
						fCount[+]: {}]

  which is the delta from adding the field.

- debugging further shows that the delta adding the type is sent out when 
  deleting the test projects.
Comment 1 Jerome Lanneluc CLA 2003-10-29 13:37:01 EST
Problem due to a change in the behavior of IWorkspace.isTreeLocked(). It 
returns true even if the tree is not locked.

May want to undo the workaround described in bug 29585.
Comment 2 John Arthorne CLA 2003-10-29 14:01:38 EST
If the behaviour of isTreeLocked has changed, it is a bug.  Please enter a bug
with platform core if this is the case.
Comment 3 Jerome Lanneluc CLA 2003-10-29 17:26:35 EST
After further investigation, it appears that the tree is marked as locked 
because another thread is in the middle of notifying resource changes after a 
build:

1. A resource is changed in thread 't1'. 
2. Another thread 't2' is spawn to do the build.
3. At the end of the build, a POST_CHANGE notification occurs.
4. During the POST_CHANGE notification, the tree is locked.
5. In 't1' testing for isTreeLocked() returns true. However IWorkspace.run(...) 
can still be used. It doesn't throw a CoreException. 
6. Tree modifications made in this IWorkspaceRunnable will just wait for the 
POST_CHANGE notification in 't2' to finish to proceed.

So the question is how do we know that using IWorkspace.run(...) will throw a 
CoreException before calling it?
Comment 4 Jerome Lanneluc CLA 2003-10-30 04:41:50 EST
Comment #3 should have been added to bug 29585.
Moving it there.
Comment 5 Jerome Lanneluc CLA 2003-10-30 06:38:44 EST
Workaround described in bug 29585 was wrong. If the operation is read only, 
then IWorkspace.run(...) should not be used. If it is not read only, 
IWorkspace.run(...) should be used. If the tree is locked, it will throw a 
CoreException which is fine because the operation will attempt to modify the 
tree.

Removed call to isTreeLocked() in JavaElement.run(...). This fixes this bug.
Comment 6 Dirk Baeumer CLA 2003-11-05 05:26:44 EST
Build N20031105 failed showing the same behaviour as described in this PR. Did 
anything change again in this area.
Comment 7 Jerome Lanneluc CLA 2003-11-05 05:53:38 EST
Might be a consequence of the last change in bug 29624
Comment 8 Dirk Baeumer CLA 2003-11-11 18:02:22 EST
The problem again nshowed up in I20031111
Comment 9 Jerome Lanneluc CLA 2003-11-12 05:42:29 EST
Cannot reproduce following the orignal steps.
Comment 10 Dirk Baeumer CLA 2003-11-12 06:05:35 EST
This time we are getting wrong deltas when adding a type to a compilation 
unit. Due to Philippe this is caused by background autobuilding. For the test 
case we have disabled autobuild. 
Comment 11 Dirk Baeumer CLA 2003-11-12 06:16:50 EST
The affected statements are:

ICompilationUnit newCU= pack.getCompilationUnit("A.java");
IType type= newCU.createType("public class A {\n}\n", null, true, null);

Comment 12 Jerome Lanneluc CLA 2003-11-12 07:15:58 EST
Same problem as described in bug 46428: a resource delta is fired too early 
even if it is run in an IWorkspaceRunnable.
Comment 13 Jerome Lanneluc CLA 2004-01-06 07:46:17 EST
Dirk, can this be closed now?
Comment 14 Dirk Baeumer CLA 2004-01-06 10:43:35 EST
We are still getting wrong deltas on class path changes. But I think this is 
covered by a different PR. So OK to close
Comment 15 Jerome Lanneluc CLA 2004-01-06 10:51:33 EST
Closing