Bug 54081 - Platform.getLocation() has a leading slash when instance data location set using File.toUrl()
Summary: Platform.getLocation() has a leading slash when instance data location set us...
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Incubator (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 2000
: P3 major (vote)
Target Milestone: 3.0 M9   Edit
Assignee: Jeff McAffer CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-03-08 15:41 EST by Nick Edgar CLA
Modified: 2005-09-27 09:12 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Edgar CLA 2004-03-08 15:41:37 EST
build I20040303, with latest UI and Runtime from head, plus workspace prompt 
patch (bug 32147).

- start target with @noDefault as its workspace location (-data arg)
- choose a workspace directory like d:\eclipse-new\browser-workspace
- it opens the workspace
- create a new project A
- get properties on the project
- the info page shows the location as \d:\eclipse-new\browser-workspace
- stepping through it, Platform.getLocation() is returning a leading slash.
Comment 1 Nick Edgar CLA 2004-03-08 22:10:05 EST
Turns out this is a major problem.

I launched a target using the new workspace prompt, which sets the instance 
data location to a URL with protocol "file" and path "/d:/eclipse-
I20040303/eclipse/workspace", which was obtained with File.toURL().

I then created project A, folder A/B and file A/B/C.txt.  The editor did not 
find C.txt and it did not show up in the Navigator.  When I refreshed B, it 
disappeared.  The folder and file were there in the filesystem though.

Thinking this might be related to this bug, I changed the workspace prompt code 
to create the URL directly rather than using File.toURL(), with 
path "d:/eclipse-I20040303/eclipse/workspace".  This fixed the above problems.

Please advise on the correct format of URL to pass to the runtime.
Comment 2 Jeff McAffer CLA 2004-03-09 05:43:27 EST
The leading / is perfectly legal.  As I understand URL/URI, if you do NOT have 
a leading / the value is opaque.  Technically it means you should not be able 
to do path math etc.  In the case of URLs it seems that the implementation 
still allows this.  There have been hints that URI is more restrictive.

In any event, for backward compatibility Platform.getLocation() should be 
updated to trim the leading /s if any.  This is quite complex as there may in 
fact be /// (three /) and this would also be valid.  I believe the that new File
(aFile.toURL().getPath()) should always work.

As a workaround in the near term the workspace prompt should be careful to not 
put the / in.

Passing to Pascal as he was also looking at a case where the install location 
having spaces caused issues.  This may be related to not encoding the URL 
(converting ' ' to '+', ...)
Comment 3 Nick Edgar CLA 2004-03-09 08:05:48 EST
I noticed in the spec for File.toURL() that it says it does not do character 
conversion.  They suggest converting to a URI first for new code: File.toURI
().toURL().
Comment 4 Andrew Eidsness CLA 2004-03-09 09:46:42 EST
I tried the File.toURI().toURL() approach but got the same results as just toURL 
-- i.e., it didn't work.

For the workspace prompt (for now) I'll build the URL using a constructor; 
hopefully in the future we'll be able to go back to the File.toURL approach.
Comment 5 Jeff McAffer CLA 2004-04-30 22:27:09 EDT
For consistency lets just ensure that the result of getLocation does NOT have a 
leading /.  This is the right answre for compatibility.
Comment 6 Nick Edgar CLA 2004-05-05 20:15:58 EDT
I also notice that if you run with -showLocation, the path that's shown in the
titlebar has a trailing slash, which I don't think it did before.
Comment 7 Jeff McAffer CLA 2004-05-07 01:11:09 EDT
I tried 2.1 with -showLocation and found that it basically reports whatever you 
set in the -data arg.  start with -data c:\foo and you get "c:\foo".  Use -data 
c:\foo\ and that is what -showLocation displays.

In any event, I have changed getLocation() to "normalize" the value (used new 
File(value).toString() as the approved way of normalizing a file location in 
Java (see java.io.FileSystem)).  This means that it will not have a leading \ 
(before the device) and will not have a trailing \.  This last point does not 
appear to be spec'd anywhere that I could see but is the behaviour observed on 
JDK 1.4.2_04.

I want to do a bit more testing before releasing
Comment 8 Jeff McAffer CLA 2004-05-07 03:10:43 EDT
released.