### 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.442 diff -u -r1.442 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 10 Dec 2009 18:45:24 -0000 1.442 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 15 Feb 2010 16:30:39 -0000 @@ -4323,6 +4323,8 @@ ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom(file, null); IType type = unit.getType(typeName); types.put(typeName, type); // replace stored path with type itself + } else { + types.remove(typeName); } } } @@ -4828,6 +4830,20 @@ public void contentTypeChanged(ContentTypeChangeEvent event) { Util.resetJavaLikeExtensions(); + // Walk through projects to reset their secondary types cache + IJavaProject[] projects; + try { + projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects(); + } catch (JavaModelException e) { + return; + } + for (int i = 0, length = projects.length; i < length; i++) { + IJavaProject project = projects[i]; + final PerProjectInfo projectInfo = getPerProjectInfo(project.getProject(), false /* don't create info */); + if (projectInfo != null) { + projectInfo.secondaryTypes = null; + } + } } public synchronized String cacheToString(String prefix) { Index: model/org/eclipse/jdt/internal/core/NameLookup.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/NameLookup.java,v retrieving revision 1.126 diff -u -r1.126 NameLookup.java --- model/org/eclipse/jdt/internal/core/NameLookup.java 20 Apr 2009 20:40:14 -0000 1.126 +++ model/org/eclipse/jdt/internal/core/NameLookup.java 15 Feb 2010 16:30:39 -0000 @@ -583,12 +583,6 @@ * Find secondary type for a project. */ private IType findSecondaryType(String packageName, String typeName, IJavaProject project, boolean waitForIndexes, IProgressMonitor monitor) { - if (JavaModelManager.VERBOSE) { - Util.verbose("NameLookup FIND SECONDARY TYPES:"); //$NON-NLS-1$ - Util.verbose(" -> pkg name: " + packageName); //$NON-NLS-1$ - Util.verbose(" -> type name: " + typeName); //$NON-NLS-1$ - Util.verbose(" -> project: "+project.getElementName()); //$NON-NLS-1$ - } JavaModelManager manager = JavaModelManager.getJavaModelManager(); try { IJavaProject javaProject = project; @@ -599,6 +593,10 @@ IType type = (IType) types.get(typeName); if (type != null) { if (JavaModelManager.VERBOSE) { + Util.verbose("NameLookup FIND SECONDARY TYPES:"); //$NON-NLS-1$ + Util.verbose(" -> pkg name: " + packageName); //$NON-NLS-1$ + Util.verbose(" -> type name: " + typeName); //$NON-NLS-1$ + Util.verbose(" -> project: "+project.getElementName()); //$NON-NLS-1$ Util.verbose(" -> type: " + type.getElementName()); //$NON-NLS-1$ } return type; #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/ClassNameTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassNameTests.java,v retrieving revision 1.18 diff -u -r1.18 ClassNameTests.java --- src/org/eclipse/jdt/core/tests/model/ClassNameTests.java 27 Jun 2008 16:02:40 -0000 1.18 +++ src/org/eclipse/jdt/core/tests/model/ClassNameTests.java 15 Feb 2010 16:30:41 -0000 @@ -16,6 +16,8 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.ICompilationUnit; import org.eclipse.jdt.core.IJavaProject; @@ -1244,4 +1246,48 @@ deleteProject("P"); } } + +/** + * @bug 302455: java.lang.ClassCastException in secondary types removal + * @test Ensure that no invalid entries are put in the secondary types caches + * when a file extension spec is removed from the workspace as the CCE + * does no longer occur... + * Also verify that secondary types from the removed file extension are not + * kept in the projects caches as the secondary type is no longer in the + * cache at the end of the test... + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=302455" + */ +public void testBug302455() throws CoreException, InterruptedException { + IContentType javaContentType = Platform.getContentTypeManager().getContentType(JavaCore.JAVA_SOURCE_CONTENT_TYPE); + try { + // Create project and file + assertNotNull("We should have got a Java Source content type!", javaContentType); + javaContentType.addFileSpec("b302455", IContentType.FILE_EXTENSION_SPEC); + IJavaProject javaProject = createJavaProject("P"); + createFolder("/P/p"); + String filePath = "/P/p/Bug.b302455"; + createFile( + filePath, + "package p;\n" + + "public class Bug {}\n" + + "class Secondary {}\n" + + "" + ); + waitUntilIndexesReady(); + + // Get the secondary type + IType type = javaProject.findType("p.Secondary", new NullProgressMonitor()); + assertNotNull("We should have found the secondary type!", type); + + // Remove file extension + org.eclipse.jdt.internal.core.JavaModelManager.VERBOSE = true; + javaContentType.removeFileSpec("b302455", IContentType.FILE_EXTENSION_SPEC); + + // As there's no specific event fo + type = javaProject.findType("p.Secondary", new NullProgressMonitor()); + assertNull("We should have not found the secondary type!", type); + } finally { + deleteProject("P"); + } +} }