fix exception from buildpath changes on windows, bug 401623
diff --git a/core/plugins/org.eclipse.dltk.core/environment/org/eclipse/dltk/core/environment/EnvironmentPathUtils.java b/core/plugins/org.eclipse.dltk.core/environment/org/eclipse/dltk/core/environment/EnvironmentPathUtils.java
index ef6683c..51814b0 100644
--- a/core/plugins/org.eclipse.dltk.core/environment/org/eclipse/dltk/core/environment/EnvironmentPathUtils.java
+++ b/core/plugins/org.eclipse.dltk.core/environment/org/eclipse/dltk/core/environment/EnvironmentPathUtils.java
@@ -229,4 +229,19 @@
 		}
 	}
 
+	/**
+	 * Answers if the specified full path belongs to the local environment.
+	 */
+	public static boolean isLocalEnvironment(IPath fullPath) {
+		final String device = fullPath.getDevice();
+		if (device != null) {
+			final int pos = device.indexOf(SEPARATOR);
+			if (pos >= 0) {
+				return LocalEnvironment.ENVIRONMENT_ID.equals(device.substring(
+						0, pos));
+			}
+		}
+		return false;
+	}
+
 }
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ExternalFolderChange.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ExternalFolderChange.java
index 1bc8a9b..caf7190 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ExternalFolderChange.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ExternalFolderChange.java
@@ -11,7 +11,6 @@
 package org.eclipse.dltk.internal.core;
 
 import java.util.HashSet;
-import java.util.Iterator;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
@@ -35,25 +34,23 @@
 	 */
 	public void updateExternalFoldersIfNecessary(boolean refreshIfExistAlready,
 			IProgressMonitor monitor) throws ModelException {
-		HashSet oldFolders = ExternalFoldersManager
+		HashSet<IPath> oldFolders = ExternalFoldersManager
 				.getExternalFolders(this.oldResolvedBuildpath);
 		IBuildpathEntry[] newResolvedBuildpath = this.project
 				.getResolvedBuildpath();
-		HashSet newFolders = ExternalFoldersManager
+		HashSet<IPath> newFolders = ExternalFoldersManager
 				.getExternalFolders(newResolvedBuildpath);
 		if (newFolders == null)
 			return;
 		ExternalFoldersManager foldersManager = ModelManager
 				.getExternalManager();
-		Iterator iterator = newFolders.iterator();
-		while (iterator.hasNext()) {
-			Object folderPath = iterator.next();
+		for (IPath folderPath : newFolders) {
 			if (oldFolders == null || !oldFolders.remove(folderPath)) {
 				try {
-					foldersManager.createLinkFolder((IPath) folderPath,
+					foldersManager.createLinkFolder(folderPath,
 							refreshIfExistAlready, monitor);
 				} catch (CoreException e) {
-					throw new ModelException(e);
+					ModelException.propagate(e);
 				}
 			}
 		}
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ExternalFoldersManager.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ExternalFoldersManager.java
index 34fb6fd..64cff85 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ExternalFoldersManager.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ExternalFoldersManager.java
@@ -28,9 +28,11 @@
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.dltk.annotations.Nullable;
 import org.eclipse.dltk.core.DLTKCore;
 import org.eclipse.dltk.core.IBuildpathEntry;
 import org.eclipse.dltk.core.IScriptProjectFilenames;
+import org.eclipse.dltk.core.environment.EnvironmentPathUtils;
 import org.eclipse.dltk.internal.core.util.Util;
 
 public class ExternalFoldersManager {
@@ -43,18 +45,23 @@
 	 * Returns a set of external path to external folders referred to on the
 	 * given buildpath. Returns null if none.
 	 */
-	public static HashSet getExternalFolders(IBuildpathEntry[] buildpath) {
+	@Nullable
+	public static HashSet<IPath> getExternalFolders(IBuildpathEntry[] buildpath) {
 		if (buildpath == null)
 			return null;
-		HashSet folders = null;
+		HashSet<IPath> folders = null;
 		for (int i = 0; i < buildpath.length; i++) {
 			IBuildpathEntry entry = buildpath[i];
 			if (entry.getEntryKind() == IBuildpathEntry.BPE_LIBRARY) {
 				IPath entryPath = entry.getPath();
-				if (isExternalFolderPath(entryPath)) {
-					if (folders == null)
-						folders = new HashSet();
-					folders.add(entryPath);
+				if (EnvironmentPathUtils.isLocalEnvironment(entryPath)) {
+					final IPath local = EnvironmentPathUtils
+							.getLocalPath(entryPath);
+					if (isExternalFolderPath(local)) {
+						if (folders == null)
+							folders = new HashSet<IPath>();
+						folders.add(local);
+					}
 				}
 			}
 		}
diff --git a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ScriptProject.java b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ScriptProject.java
index dd5c815..b0b1a48 100644
--- a/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ScriptProject.java
+++ b/core/plugins/org.eclipse.dltk.core/model/org/eclipse/dltk/internal/core/ScriptProject.java
@@ -942,11 +942,11 @@
 		ExternalFoldersManager externalFoldersManager = ModelManager
 				.getExternalManager();
 		ResolvedBuildpath result = new ResolvedBuildpath();
-		Map knownDrives = new HashMap();
+		Map<String, Boolean> knownDrives = new HashMap<String, Boolean>();
 
 		Map referencedEntriesMap = new HashMap();
 		List<IPath> rawLibrariesPath = new ArrayList<IPath>();
-		LinkedHashSet resolvedEntries = new LinkedHashSet();
+		LinkedHashSet<IBuildpathEntry> resolvedEntries = new LinkedHashSet<IBuildpathEntry>();
 
 		if (resolveChainedLibraries) {
 			for (int index = 0; index < rawClasspath.length; index++) {
@@ -1125,9 +1125,10 @@
 
 	private void addToResult(IBuildpathEntry rawEntry,
 			IBuildpathEntry resolvedEntry, ResolvedBuildpath result,
-			LinkedHashSet resolvedEntries,
+			LinkedHashSet<IBuildpathEntry> resolvedEntries,
 			ExternalFoldersManager externalFoldersManager,
-			Map oldChainedEntriesMap, boolean addAsChainedEntry, Map knownDrives) {
+			Map oldChainedEntriesMap, boolean addAsChainedEntry,
+			Map<String, Boolean> knownDrives) {
 
 		IPath resolvedPath;
 		// If it's already been resolved, do not add to resolvedEntries
@@ -1192,11 +1193,12 @@
 	 * File#exists() takes lot of time for an unmapped drive. Hence, cache the
 	 * info. https://bugs.eclipse.org/bugs/show_bug.cgi?id=338649
 	 */
-	private boolean driveExists(IPath sourcePath, Map knownDrives) {
+	private boolean driveExists(IPath sourcePath,
+			Map<String, Boolean> knownDrives) {
 		String drive = sourcePath.getDevice();
 		if (drive == null)
 			return true;
-		Boolean good = (Boolean) knownDrives.get(drive);
+		Boolean good = knownDrives.get(drive);
 		if (good == null) {
 			if (new File(drive).exists()) {
 				knownDrives.put(drive, Boolean.TRUE);