Bug 571164: Two IContainer instances can share same location

When updating the container for a launch configuration, make sure that
the new and the old container do not point to the same location.
Nested projects can have different container instances that points to
the same location and a switch between these containers should not be
considered a "move" of the launch configuration.

Contributed by STMicroelectronics

Change-Id: I504f351b8ae9a6544c86659f99151a81059a7e38
Signed-off-by: Torbjörn Svensson <torbjorn.svensson@st.com>
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationWorkingCopy.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationWorkingCopy.java
index 0141dd4..8a4959b 100644
--- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationWorkingCopy.java
+++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/LaunchConfigurationWorkingCopy.java
@@ -25,6 +25,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 
 import org.eclipse.core.filesystem.EFS;
@@ -35,6 +36,7 @@
 import org.eclipse.core.resources.IWorkspaceRunnable;
 import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.NullProgressMonitor;
@@ -608,13 +610,8 @@
 		}
 		IContainer newContainer = getContainer();
 		IContainer originalContainer = ((LaunchConfiguration)getOriginal()).getContainer();
-		if (newContainer == originalContainer) {
-			return false;
-		}
-		if (newContainer == null) {
-			return !originalContainer.equals(newContainer);
-		}
-		return !newContainer.equals(originalContainer);
+
+		return !isSameContainerLocation(newContainer, originalContainer);
 	}
 
 	/**
@@ -636,9 +633,22 @@
 		return fSuppressChange;
 	}
 
+	private boolean isSameContainerLocation(IContainer newContainer, IContainer originalContainer) {
+		// Verify that containers are not nested
+		if (newContainer != null && originalContainer != null) {
+			IPath newPath = newContainer.getLocation();
+			IPath originalPath = originalContainer.getLocation();
+
+			if (Objects.equals(newPath, originalPath)) {
+				return true;
+			}
+		}
+		return Objects.equals(newContainer, originalContainer);
+	}
+
 	@Override
 	public void setContainer(IContainer container) {
-		if (equalOrNull(getContainer(), container)) {
+		if (isSameContainerLocation(container, getContainer())) {
 			return;
 		}
 		super.setContainer(container);