Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 359956 - Creating a file in place of a linked resources, then deleting that linked resource from the .project file leaves the workspace in an inconsistent state.
Summary: Creating a file in place of a linked resources, then deleting that linked res...
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Resources (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Serge Beauchamp CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-05 05:40 EDT by Serge Beauchamp CLA
Modified: 2020-03-10 16:16 EDT (History)
2 users (show)

See Also:
serge: review? (Szymon.Brandys)


Attachments
Fix (1.65 KB, patch)
2011-10-05 05:44 EDT, Serge Beauchamp CLA
no flags Details | Diff
Fix and JUnit test (15.38 KB, patch)
2012-05-04 12:14 EDT, Serge Beauchamp CLA
no flags Details | Diff
Fix and JUnit test (15.38 KB, patch)
2012-05-04 12:20 EDT, Serge Beauchamp CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Serge Beauchamp CLA 2011-10-05 05:40:52 EDT
Creating a file in place of a linked resources, then deleting that linked resource from the .project file leaves the workspace in an inconsistent state.

Reproducibility steps:

1) create a new project "p1"
2) create a new folder under "p1/dir" in Eclipse
3) create a new file "foo.c" in Windows Explorer, under the "p1" folder (c:\wksp\p1\foo.c for example)
4) drag and drop foo.c from Windows Explorer under "p1/dir" in the Eclipse Workbench
5) click ok to create a linked file
6) Edit the newly created p1/dir/foo.c linked resource, and change its location to PROJECT_LOC\dir\foo.c
6) In Windows Explorer, move p1\foo.c to p1\dir\foo.c
7) close p1 in the Eclipse Workbench
8) open p1/.project in notepad, and remove the following lines:

	<linkedResources>
		<link>
			<name>dir/foo.c</name>
			<type>1</type>
			<locationURI>PROJECT_LOC/dir/foo.c</locationURI>
		</link>
	</linkedResources>

9) Go back to Eclipse, and open the project p1.
10) Refresh the project.
11) Notice that the resource p1/dir/foo.c is still a linked resource : this is a bug.
12) Right click on the resource p1/dir/foo.c, and notice that
   a) The 'Type' is Linked File - this is a bug
   b) The location is '<resource does not exist>  - this is a bug.
Comment 1 Serge Beauchamp CLA 2011-10-05 05:44:32 EDT
Created attachment 204577 [details]
Fix

Fix for this issue.  The approach is to have this bug resolved when the user refreshes the workspace.
Comment 2 Serge Beauchamp CLA 2011-10-05 05:45:05 EDT
Szymon, can you review this patch for me please?

Thanks.
Comment 3 Szymon Brandys CLA 2011-11-04 08:30:16 EDT
I think we may reproduce using easier steps:
1) Create a project 'p1'
2) Create a linke file under 'p1' and link it to anything
3) Close the project and remove <linkedResources> section from .project
4) Open the project and refresh
The linked file is still there. 

If just do:
1) Create a project 'p1'
2) Create a linke file under 'p1' and link it to anything
3) Remove <linkedResources> section from .project
4) Refresh .project
The linked resource will be removed.

I think that the problem is Project#reconcileLinksAndGroups? I'll check if I am right. Serge, could you attach a test?
Comment 4 Szymon Brandys CLA 2011-11-04 12:07:06 EDT
These steps fail too:
1) Create a project 'p1'
2) Create a linked file under 'p1' and link it to anything
3) Close Eclipse and remove <linkedResources> section from .project
4) Restart Eclipse and refresh 'p1'

Looking closer at #reconcileLinksAndGroups, it indeed does not do a good job for failing cases described in this bug. If linked resources were removed from .project while the project was closed, #reconcileLinksAndGroups will not remove them from the workspace.
Comment 5 Serge Beauchamp CLA 2011-12-01 11:07:52 EST
setting target to 3.8M5
Comment 6 Serge Beauchamp CLA 2012-01-20 06:16:01 EST
(In reply to comment #4)
> These steps fail too:
> 1) Create a project 'p1'
> 2) Create a linked file under 'p1' and link it to anything
> 3) Close Eclipse and remove <linkedResources> section from .project
> 4) Restart Eclipse and refresh 'p1'
> 
> Looking closer at #reconcileLinksAndGroups, it indeed does not do a good job
> for failing cases described in this bug. If linked resources were removed from
> .project while the project was closed, #reconcileLinksAndGroups will not remove
> them from the workspace.

How can #reconcileLinksAndGroups get the list of linked resources in the workspace, and validate them against the description.getLinks() list without a visitor?

It seems like adding a visitor in #reconcileLinksAndGroups would be more of a performance issue than the current fix in the RefreshLocalVisitor, what do you think?
Comment 7 Szymon Brandys CLA 2012-03-07 04:52:10 EST
Sege, still in the plan for M6? We do not have much time.
Comment 8 Serge Beauchamp CLA 2012-04-30 16:08:15 EDT
your suggestion looks good Szymon, I'll get back to you tomorrow with a fix.
Comment 9 Serge Beauchamp CLA 2012-05-04 12:14:41 EDT
Created attachment 215072 [details]
Fix and JUnit test

Here's a new fix moving the resolution to the reconcile() code instead of in the RefreshVisitor code.
Comment 10 Serge Beauchamp CLA 2012-05-04 12:20:42 EDT
Created attachment 215073 [details]
Fix and JUnit test

Again, but with less spurious changes.
Comment 11 Serge Beauchamp CLA 2012-05-04 12:24:13 EDT
(In reply to comment #10)
> Created attachment 215073 [details]
> Fix and JUnit test
> 
> Again, but with less spurious changes.

I'm not sure where the line changes are comming from, since I verified twice I only changed the reconcileLinksAndGroups() method in Project.java.

The diff is misleading in terms of how much change there is.  To summarize it, this was the old implementation:

reconcileLinksAndGroups() {
  // old code
}

The new implementation looks like that:

reconcileLinksAndGroups() {
  try {
    // old code
  } finally {
    // new code
  }
}

Szymon, can you review the changes please?  thanks.
Comment 12 Eclipse Genie CLA 2020-03-10 16:16:48 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.