Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 117824 - [implementation] org.eclipse.core.filebuffers.FileBuffers#normalizeLocation returns inconsistent normalized path
Summary: [implementation] org.eclipse.core.filebuffers.FileBuffers#normalizeLocation r...
Status: RESOLVED INVALID
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.2   Edit
Assignee: Platform-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-11-23 22:24 EST by Hirotaka Matsumoto CLA
Modified: 2006-04-07 19:32 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Hirotaka Matsumoto CLA 2005-11-23 22:24:44 EST
org.eclipse.core.filebuffers.FileBuffers#normalizeLocation returns
different normalized IPath. Here is the detail.

Given that the workspace location is "C:\workspace", and there are no
files. Then, when we run the follwoing code,

IPath path1 = new Path("C:/workspace/nonexistingfile");
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path1);

IPath path2 = FileBuffers.normalizeLocation(file.getLocation());
IPath path3 = FileBuffers.normalizeLocation(file.getFullPath());

path2.toString() is "C:/workspace/nonexistingfile", whereas
path3.toString() is "/nonexistingfile".

The key is that if path1 points to the existing file, both cases return
the same normalized path ("/existingfile") as its java doc says, 
yet if path1 points to the non-existing file, they are different. According
to its java doc,

    For a path to a non-existing workspace file, the normalized form is the
    absolute form of the path.

and I guess this differenece comes from IPath#makeAbsolute's behaviour.
I really don't know this difference is what is suppoed to be. Because some
WTP components asuume that FileBuffers#normalizeLocation returns
the consistent IPath if the passed IPath is semantically same.
Comment 1 Dani Megert CLA 2005-11-24 10:45:13 EST
Good catch!
Comment 2 Dani Megert CLA 2006-04-06 11:08:15 EDT
The code listed in comment 0 results in an NPE since IWorkspaceRoot.getFileForLocation(IPath) returns 'null' if there's no file at the given location:

	 * @return the corresponding file in the workspace,
	 *    or <code>null</code> if none
Comment 3 Hirotaka Matsumoto CLA 2006-04-06 22:00:31 EDT
Ah, the test case has a bug. Need a project. Both, the workspace and the project
itself need to exist. 

Given that the workspace location is "C:\workspace", and
the project location is "C:\workspace\project"  and there are no files under 
this project, the revised test case is :

IPath path1 = new Path("C:/workspace/project/nonexistingfile");
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path1);

IPath path2 = FileBuffers.normalizeLocation(file.getLocation());
IPath path3 = FileBuffers.normalizeLocation(file.getFullPath());

path2.toString() is "C:/workspace/project/nonexistingfile", whereas
path3.toString() is "/project/nonexistingfile".

Note: According to IWorkspaceRoot#getFileForLocation java doc, it says :

	 * The resulting file need not exist in the workspace.

Actually, it works with 3.2M6.
Comment 4 Dani Megert CLA 2006-04-07 03:24:44 EDT
The current behavior is correct and according to the spech which says:

1) Existing Workspace Files:
    For a path or location for which there exists a workspace file, the 
    normalized form is that file's workspace relative, absolute path as
    returned by IFile#getFullPath()

2) Non-existing Workspace Files:
    For a path to a non-existing workspace file, the normalized form is the
    absolute form of the path i.e. path.makeAbsolute()

3) External Files:
    For a location for which there exists no workspace file, the normalized
    form is the absolute form of the location i.e. location.makeAbsolute()

In your example
  IPath path2 = FileBuffers.normalizeLocation(file.getLocation());
you enter a location and not a path and hence 3) is applied

While here
  IPath path3 = FileBuffers.normalizeLocation(file.getFullPath());
you enter a path and hence 2) applies.

IPath path3 = FileBuffers.normalizeLocation(file.getFullPath());
Comment 5 Hirotaka Matsumoto CLA 2006-04-07 04:18:41 EDT
David, what would you think ? If that spec is right, I would guess
some WTP usage would have a problem....


.
Comment 6 Dani Megert CLA 2006-04-07 04:48:12 EDT
I bet that WTP and many other clients would have by far more problems when we changed the contract after three years. The binding part of the API is the spec and not the implementation.

The main problem/confusion is caused by combining path and location into one parameter, see bug 99610 for a way to improve this on our side.
Comment 7 David Williams CLA 2006-04-07 19:32:34 EDT
(In reply to comment #5)
> David, what would you think ? If that spec is right, I would guess
> some WTP usage would have a problem....
> 

I believe we have already worked about this unusual spec in WTP. :) 
And, I agree, as long as it is spec'd that way, it should not be changed, 
... just "added to", or an alternative provided ... as Dani is going to do 
in bug 99610. 

If you still see a problem in WTP related to this, let us know.