### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/JavaModelManager.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/JavaModelManager.java,v retrieving revision 1.445 diff -u -r1.445 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 2 Mar 2010 06:46:01 -0000 1.445 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 23 Mar 2010 15:12:07 -0000 @@ -1552,9 +1552,8 @@ } public void addNonChainingJar(IPath path) { - if (this.nonChainingJars == null) - return; - this.nonChainingJars.add(path); + if (this.nonChainingJars != null) + this.nonChainingJars.add(path); } /** @@ -2922,7 +2921,7 @@ } private Set loadNonChainingJarsCache() { - Set nonChainingJarsCache = Collections.synchronizedSet(new HashSet()); + Set nonChainingJarsCache = new HashSet(); File nonChainingJarsFile = getNonChainingJarsFile(); DataInputStream in = null; try { @@ -2944,7 +2943,7 @@ } } } - return nonChainingJarsCache; + return Collections.synchronizedSet(nonChainingJarsCache); } private File getNonChainingJarsFile() { @@ -2952,9 +2951,12 @@ } private Set getNonChainingJarsCache() throws CoreException { - if (this.nonChainingJars != null) + // Even if there is one entry in the cache, just return it. It may not be + // the complete cache, but avoid going through all the projects to populate the cache. + if (this.nonChainingJars != null && this.nonChainingJars.size() > 0) { return this.nonChainingJars; - Set result = Collections.synchronizedSet(new HashSet()); + } + Set result = new HashSet(); IJavaProject[] projects = getJavaModel().getJavaProjects(); for (int i = 0, length = projects.length; i < length; i++) { IJavaProject javaProject = projects[i]; @@ -2969,7 +2971,8 @@ } } } - return result; + this.nonChainingJars = Collections.synchronizedSet(result); + return this.nonChainingJars; } public void loadVariablesAndContainers() throws CoreException { @@ -3648,6 +3651,7 @@ info.forgetExternalTimestampsAndIndexes(); } } + resetNonChainingJarsCache(); } /* @@ -3690,7 +3694,8 @@ } public void resetNonChainingJarsCache() { - this.nonChainingJars = null; + if (this.nonChainingJars != null) + this.nonChainingJars.clear(); } /* #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/ClasspathTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java,v retrieving revision 1.209 diff -u -r1.209 ClasspathTests.java --- src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 4 Mar 2010 10:11:58 -0000 1.209 +++ src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 23 Mar 2010 15:12:14 -0000 @@ -6579,5 +6579,67 @@ this.deleteProject("P"); } } +/** + * @bug 302949: FUP of 302949 + * Test that + * 1) non-chaining jars are cached during classpath resolution and can be retrieved later on + * 2) A full save (after resetting the non chaining jars cache) caches the non-chaining jars information + * 3) when a project is deleted, the non-chaining jar cache is reset. + * + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=305122" + * @throws Exception + */ +public void testBug305122() throws Exception { + try { + + IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin"); + IClasspathEntry[] classpath = new IClasspathEntry[2]; + + addLibrary(proj, "nonchaining.jar", null, new String[0], + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n", + }, + JavaCore.VERSION_1_4); + addLibrary(proj, "chaining.jar", null, new String[0], + new String[] { + "META-INF/MANIFEST.MF", + "Manifest-Version: 1.0\n" + + "Class-Path: chained.jar\n", + }, + JavaCore.VERSION_1_4); + + classpath[0] = JavaCore.newLibraryEntry(new Path("/P/nonchaining.jar"), null, null); + classpath[1] = JavaCore.newLibraryEntry(new Path("/P/chaining.jar"), null, null); + createFile("/P/chained.jar", ""); + + proj.setRawClasspath(classpath, null); + waitForAutoBuild(); + JavaModelManager manager = JavaModelManager.getJavaModelManager(); + assertTrue("Non chaining Jar", manager.isNonChainingJar(classpath[0].getPath())); + assertFalse("Chaining Jar", manager.isNonChainingJar(classpath[1].getPath())); + + ((JavaProject)proj).resetResolvedClasspath(); + proj.getResolvedClasspath(true); + manager = JavaModelManager.getJavaModelManager(); + assertTrue("Non chaining Jar", manager.isNonChainingJar(classpath[0].getPath())); + assertFalse("Chaining Jar", manager.isNonChainingJar(classpath[1].getPath())); + + ((JavaProject)proj).resetResolvedClasspath(); + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + workspace.save(true, null); + assertTrue("Non chaining Jar", manager.isNonChainingJar(classpath[0].getPath())); + assertFalse("Chaining Jar", manager.isNonChainingJar(classpath[1].getPath())); + + this.deleteProject("P"); + assertFalse("Chaining Jar", manager.isNonChainingJar(classpath[0].getPath())); + assertFalse("Chaining Jar", manager.isNonChainingJar(classpath[1].getPath())); + + } finally { + IProject proj = this.getProject("P"); + if ( proj != null && proj.exists()) + this.deleteProject("P"); + } +} }