Bug 61329 - launch aborted when pre-req project closed
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/DefaultProjectClasspathEntry.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/DefaultProjectClasspathEntry.java
index 9c2aca1..005059f 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/DefaultProjectClasspathEntry.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/DefaultProjectClasspathEntry.java
@@ -161,7 +161,11 @@
 			return;
 		}
 		IJavaProject project = (IJavaProject)JavaCore.create(res);
-		if (project == null || !project.exists() || !project.getProject().isOpen()) {
+		IProject pj = null;
+		if (project != null) {
+			pj = project.getProject();
+		}
+		if (project == null || !pj.exists() || !pj.isOpen() || !project.exists()) {
 			// add project entry and return
 			expandedPath.add(projectEntry);
 			return;
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JavaSourceLookupUtil.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JavaSourceLookupUtil.java
index 04f397d..dfd3f71 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JavaSourceLookupUtil.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JavaSourceLookupUtil.java
@@ -147,14 +147,18 @@
 			try {
 				IJavaProject[] jps = model.getJavaProjects();
 				for (int i = 0; i < jps.length; i++) {
-					IPackageFragmentRoot[] allRoots = jps[i].getPackageFragmentRoots();
-					for (int j = 0; j < allRoots.length; j++) {
-						IPackageFragmentRoot root = allRoots[j];
-						if (root.isExternal() && root.getPath().equals(new Path(entry.getLocation()))) {
-							if (!considerSourceAttachment || isSourceAttachmentEqual(root, entry)) {
-								// use package fragment root
-								return root;
-							}							
+					IJavaProject jp = jps[i];
+					IProject p =  jp.getProject();
+					if (p.isOpen()) {
+						IPackageFragmentRoot[] allRoots = jp.getPackageFragmentRoots();
+						for (int j = 0; j < allRoots.length; j++) {
+							IPackageFragmentRoot root = allRoots[j];
+							if (root.isExternal() && root.getPath().equals(new Path(entry.getLocation()))) {
+								if (!considerSourceAttachment || isSourceAttachmentEqual(root, entry)) {
+									// use package fragment root
+									return root;
+								}							
+							}
 						}
 					}
 				}
@@ -166,7 +170,7 @@
 			IProject project = resource.getProject();
 			IJavaProject jp = JavaCore.create(project);
 			try {
-				if (jp.exists()) {
+				if (project.isOpen() && jp.exists()) {
 					IPackageFragmentRoot root = jp.getPackageFragmentRoot(resource);
 					IPackageFragmentRoot[] allRoots = jp.getPackageFragmentRoots();
 					for (int j = 0; j < allRoots.length; j++) {
@@ -185,14 +189,18 @@
 				IJavaModel model = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
 				IJavaProject[] jps = model.getJavaProjects();
 				for (int i = 0; i < jps.length; i++) {
-					IPackageFragmentRoot[] allRoots = jps[i].getPackageFragmentRoots();
-					for (int j = 0; j < allRoots.length; j++) {
-						IPackageFragmentRoot root = allRoots[j];
-						if (!root.isExternal() && root.getPath().equals(entry.getPath())) {
-							if (!considerSourceAttachment || isSourceAttachmentEqual(root, entry)) {
-								// use package fragment root
-								return root;
-							}							
+					IJavaProject jp1 = jps[i];
+					IProject p = jp1.getProject();
+					if (p.isOpen()) {
+						IPackageFragmentRoot[] allRoots = jp1.getPackageFragmentRoots();
+						for (int j = 0; j < allRoots.length; j++) {
+							IPackageFragmentRoot root = allRoots[j];
+							if (!root.isExternal() && root.getPath().equals(entry.getPath())) {
+								if (!considerSourceAttachment || isSourceAttachmentEqual(root, entry)) {
+									// use package fragment root
+									return root;
+								}							
+							}
 						}
 					}
 				}
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java
index ccef493..3a09104 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/launching/JavaRuntime.java
@@ -794,12 +794,10 @@
 				// if the project has multiple output locations, they must be returned
 				IResource resource = entry.getResource();
 				if (resource instanceof IProject) {
-					IJavaProject project = JavaCore.create((IProject)resource);
-					if (project == null || !project.exists()) { 
-						abort(MessageFormat.format(LaunchingMessages.getString("JavaRuntime.Classpath_references_non-existant_project__{0}_1"), new String[]{entry.getPath().lastSegment()}), null); //$NON-NLS-1$
-					}
-					if (!project.getProject().isOpen()) {
-						abort(MessageFormat.format(LaunchingMessages.getString("JavaRuntime.Classpath_references_closed_project__{0}_2"), new String[]{entry.getPath().lastSegment()}), null); //$NON-NLS-1$
+					IProject p = (IProject)resource;
+					IJavaProject project = JavaCore.create(p);
+					if (project == null || !p.exists() || !p.isOpen() || !project.exists()) { 
+						return new IRuntimeClasspathEntry[0];
 					}
 					IRuntimeClasspathEntry[] entries = resolveOutputLocations(project, entry.getClasspathProperty());
 					if (entries != null) {
@@ -966,12 +964,15 @@
 				// if the project has multiple output locations, they must be returned
 				IResource resource = entry.getResource();
 				if (resource instanceof IProject) {
-					IJavaProject jp = JavaCore.create((IProject)resource);
-					if (jp.exists() && jp.getProject().isOpen()) {
+					IProject p = (IProject)resource;
+					IJavaProject jp = JavaCore.create(p);
+					if (jp != null && p.exists() && p.isOpen() && jp.exists()) {
 						IRuntimeClasspathEntry[] entries = resolveOutputLocations(jp, entry.getClasspathProperty());
 						if (entries != null) {
 							return entries;
 						}
+					} else {
+						return new IRuntimeClasspathEntry[0];
 					}
 				}
 				break;