View | Details | Raw Unified | Return to bug 162104 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java (+3 lines)
Lines 583-588 Link Here
583
	if (rootPathToRawEntries != null) {
583
	if (rootPathToRawEntries != null) {
584
		rawEntry = (IClasspathEntry) rootPathToRawEntries.get(this.getPath());
584
		rawEntry = (IClasspathEntry) rootPathToRawEntries.get(this.getPath());
585
	}
585
	}
586
	if (rawEntry == null) {
587
		throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this));
588
	}
586
	return rawEntry;
589
	return rawEntry;
587
}
590
}
588
591
(-)src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java (+47 lines)
Lines 26-31 Link Here
26
import org.eclipse.jdt.core.tests.model.ClasspathInitializerTests.DefaultContainerInitializer;
26
import org.eclipse.jdt.core.tests.model.ClasspathInitializerTests.DefaultContainerInitializer;
27
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
27
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
28
import org.eclipse.jdt.internal.core.JavaModelManager;
28
import org.eclipse.jdt.internal.core.JavaModelManager;
29
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
29
import org.eclipse.jdt.internal.core.UserLibrary;
30
import org.eclipse.jdt.internal.core.UserLibrary;
30
import org.eclipse.jdt.internal.core.UserLibraryManager;
31
import org.eclipse.jdt.internal.core.UserLibraryManager;
31
import org.eclipse.jdt.internal.core.util.Util;
32
import org.eclipse.jdt.internal.core.util.Util;
Lines 1041-1046 Link Here
1041
		JavaCore.removeClasspathVariable("MyVar", null);
1042
		JavaCore.removeClasspathVariable("MyVar", null);
1042
	}
1043
	}
1043
}
1044
}
1045
/**
1046
 * @bug 162104: NPE in PackageExplorerContentProvider.getPackageFragmentRoots()
1047
 * @test That a JME is thrown when a classpath entry is no longer on the classpath
1048
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=162104"
1049
 */
1050
public void testPackageFragmentRootNullRawEntry() throws CoreException, IOException {
1051
	File libDir = null;
1052
	try {
1053
		String libPath = getExternalPath() + "lib";
1054
		JavaCore.setClasspathVariable("MyVar", new Path(libPath), null);
1055
		IJavaProject proj =  this.createJavaProject("P", new String[] {}, "bin");
1056
		libDir = new File(libPath);
1057
		libDir.mkdirs();
1058
		final int length = 10;
1059
		IClasspathEntry[] classpath = new IClasspathEntry[length];
1060
		for (int i = 0; i < length; i++){
1061
			File libJar = new File(libDir, "lib"+i+".jar");
1062
			libJar.createNewFile();
1063
			classpath[i] = JavaCore.newVariableEntry(new Path("/MyVar/lib"+i+".jar"), null, null);
1064
		}
1065
		proj.setRawClasspath(classpath, null);
1066
1067
		IPackageFragmentRoot[] roots = proj.getPackageFragmentRoots();
1068
		assertEquals("wrong number of entries:", length, roots.length);
1069
1070
		// remove last classpath entry
1071
		System.arraycopy(classpath, 0, classpath = new IClasspathEntry[length-1], 0, length-1);
1072
		proj.setRawClasspath(classpath, null);
1073
1074
		// verify that JME occurs
1075
		IPackageFragmentRoot lastRoot = roots[length-1];
1076
		String rootPath = ((PackageFragmentRoot)lastRoot).toStringWithAncestors();
1077
		try {
1078
			IClasspathEntry rawEntry = roots[length-1].getRawClasspathEntry();
1079
			assertNotNull("We should no longer get a null classpath entry:", rawEntry);
1080
		} catch (JavaModelException jme) {
1081
			assertStatus(rootPath+" is not on its project's build path", jme.getJavaModelStatus());
1082
		}
1083
	} finally {
1084
		if (libDir != null) {
1085
			org.eclipse.jdt.core.tests.util.Util.delete(libDir);
1086
		}
1087
		this.deleteProject("P");
1088
		JavaCore.removeClasspathVariable("MyVar", null);
1089
	}
1090
}
1044
/*
1091
/*
1045
 * Ensures that opening a project update the project references
1092
 * Ensures that opening a project update the project references
1046
 * (regression test for bug 73253 [model] Project references not set on project open)
1093
 * (regression test for bug 73253 [model] Project references not set on project open)

Return to bug 162104