WorkspaceFactory should use canonical URis as keys for the workspaces map
diff --git a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/WorkspaceFactory.java b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/WorkspaceFactory.java index 55dc575..fa3184b 100644 --- a/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/WorkspaceFactory.java +++ b/bundles/org.eclipse.core.resources/src/org/eclipse/core/internal/resources/WorkspaceFactory.java
@@ -14,6 +14,7 @@ import java.util.HashMap; import java.util.Map; import org.eclipse.core.filesystem.URIUtil; +import org.eclipse.core.internal.utils.FileUtil; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceFactory; import org.eclipse.core.runtime.CoreException; @@ -31,6 +32,8 @@ * @see org.eclipse.core.resources.IWorkspaceFactory#getWorkspace(java.net.URI) */ public synchronized IWorkspace constructWorkspace(URI location) throws CoreException { + // use a canonical form + location = FileUtil.canonicalURI(location); Workspace result = (Workspace) workspaces.get(location); if (result == null) { result = new Workspace(URIUtil.toPath(location)); @@ -40,5 +43,4 @@ } return result; } - }
diff --git a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MultipleWorkspacesTest.java b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MultipleWorkspacesTest.java index e008237..c834d30 100644 --- a/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MultipleWorkspacesTest.java +++ b/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/MultipleWorkspacesTest.java
@@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.core.tests.resources; +import java.net.URI; +import java.net.URISyntaxException; import junit.framework.Test; import junit.framework.TestSuite; import org.eclipse.core.filesystem.IFileStore; @@ -42,7 +44,6 @@ } public void testCreateAndListProjects() { - // create and open a non-default workspace IFileStore workspace1Location = getTempStore().getChild(getUniqueString()); IWorkspace newWorkspace1 = null; @@ -74,4 +75,35 @@ fail("5.99", e); } } + + public void testConstructWorkspace_similarURIs() { + // create and open a non-default workspace + IFileStore workspace1Location = getTempStore().getChild(getUniqueString()); + IWorkspace newWorkspace = null; + try { + newWorkspace = getWorkspaceFactory().constructWorkspace(workspace1Location.toURI()); + } catch (CoreException e) { + fail("1.0", e); + } + + // create a non-canonical workspace location URI + URI workspace1LocationURI = workspace1Location.toURI(); + URI workspaceLocationURI_nonCanonical = null; + try { + workspaceLocationURI_nonCanonical = new URI(workspace1LocationURI.toString() + "/"); + } catch (URISyntaxException e1) { + fail("2.0", e1); + } + + // get the workspace using the non-canonical location URI + IWorkspace newWorkspace2 = null; + try { + newWorkspace2 = getWorkspaceFactory().constructWorkspace(workspaceLocationURI_nonCanonical); + } catch (CoreException e) { + fail("3.0", e); + } + + // we should get the same workspace instance + assertTrue("4.0", newWorkspace == newWorkspace2); + } }