### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java,v retrieving revision 1.123 diff -u -r1.123 PackageFragmentRoot.java --- model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java 13 Apr 2007 16:02:15 -0000 1.123 +++ model/org/eclipse/jdt/internal/core/PackageFragmentRoot.java 26 Apr 2007 11:33:51 -0000 @@ -583,6 +583,9 @@ if (rootPathToRawEntries != null) { rawEntry = (IClasspathEntry) rootPathToRawEntries.get(this.getPath()); } + if (rawEntry == null) { + throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.ELEMENT_NOT_ON_CLASSPATH, this)); + } return rawEntry; } #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java,v retrieving revision 1.83 diff -u -r1.83 JavaProjectTests.java --- src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java 10 Apr 2007 13:49:15 -0000 1.83 +++ src/org/eclipse/jdt/core/tests/model/JavaProjectTests.java 26 Apr 2007 11:33:53 -0000 @@ -26,6 +26,7 @@ import org.eclipse.jdt.core.tests.model.ClasspathInitializerTests.DefaultContainerInitializer; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.core.JavaModelManager; +import org.eclipse.jdt.internal.core.PackageFragmentRoot; import org.eclipse.jdt.internal.core.UserLibrary; import org.eclipse.jdt.internal.core.UserLibraryManager; import org.eclipse.jdt.internal.core.util.Util; @@ -1041,6 +1042,52 @@ JavaCore.removeClasspathVariable("MyVar", null); } } +/** + * @bug 162104: NPE in PackageExplorerContentProvider.getPackageFragmentRoots() + * @test That a JME is thrown when a classpath entry is no longer on the classpath + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=162104" + */ +public void testPackageFragmentRootNullRawEntry() throws CoreException, IOException { + File libDir = null; + try { + String libPath = getExternalPath() + "lib"; + JavaCore.setClasspathVariable("MyVar", new Path(libPath), null); + IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin"); + libDir = new File(libPath); + libDir.mkdirs(); + final int length = 10; + IClasspathEntry[] classpath = new IClasspathEntry[length]; + for (int i = 0; i < length; i++){ + File libJar = new File(libDir, "lib"+i+".jar"); + libJar.createNewFile(); + classpath[i] = JavaCore.newVariableEntry(new Path("/MyVar/lib"+i+".jar"), null, null); + } + proj.setRawClasspath(classpath, null); + + IPackageFragmentRoot[] roots = proj.getPackageFragmentRoots(); + assertEquals("wrong number of entries:", length, roots.length); + + // remove last classpath entry + System.arraycopy(classpath, 0, classpath = new IClasspathEntry[length-1], 0, length-1); + proj.setRawClasspath(classpath, null); + + // verify that JME occurs + IPackageFragmentRoot lastRoot = roots[length-1]; + String rootPath = ((PackageFragmentRoot)lastRoot).toStringWithAncestors(); + try { + IClasspathEntry rawEntry = roots[length-1].getRawClasspathEntry(); + assertNotNull("We should no longer get a null classpath entry:", rawEntry); + } catch (JavaModelException jme) { + assertStatus(rootPath+" is not on its project's build path", jme.getJavaModelStatus()); + } + } finally { + if (libDir != null) { + org.eclipse.jdt.core.tests.util.Util.delete(libDir); + } + this.deleteProject("P"); + JavaCore.removeClasspathVariable("MyVar", null); + } +} /* * Ensures that opening a project update the project references * (regression test for bug 73253 [model] Project references not set on project open)