View | Details | Raw Unified | Return to bug 302455
Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/JavaModelManager.java (+16 lines)
Lines 4323-4328 Link Here
4323
					ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom(file, null);
4323
					ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom(file, null);
4324
					IType type = unit.getType(typeName);
4324
					IType type = unit.getType(typeName);
4325
					types.put(typeName, type); // replace stored path with type itself
4325
					types.put(typeName, type); // replace stored path with type itself
4326
				} else {
4327
					types.remove(typeName);
4326
				}
4328
				}
4327
			}
4329
			}
4328
		}
4330
		}
Lines 4828-4833 Link Here
4828
	public void contentTypeChanged(ContentTypeChangeEvent event) {
4830
	public void contentTypeChanged(ContentTypeChangeEvent event) {
4829
		Util.resetJavaLikeExtensions();
4831
		Util.resetJavaLikeExtensions();
4830
4832
4833
		// Walk through projects to reset their secondary types cache
4834
		IJavaProject[] projects;
4835
		try {
4836
			projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
4837
		} catch (JavaModelException e) {
4838
			return;
4839
		}
4840
		for (int i = 0, length = projects.length; i < length; i++) {
4841
			IJavaProject project = projects[i];
4842
			final PerProjectInfo projectInfo = getPerProjectInfo(project.getProject(), false /* don't create info */);
4843
			if (projectInfo != null) {
4844
				projectInfo.secondaryTypes = null;
4845
			}
4846
		}
4831
	}
4847
	}
4832
4848
4833
	public synchronized String cacheToString(String prefix) {
4849
	public synchronized String cacheToString(String prefix) {
(-)model/org/eclipse/jdt/internal/core/NameLookup.java (-6 / +4 lines)
Lines 583-594 Link Here
583
	 * Find secondary type for a project.
583
	 * Find secondary type for a project.
584
	 */
584
	 */
585
	private IType findSecondaryType(String packageName, String typeName, IJavaProject project, boolean waitForIndexes, IProgressMonitor monitor) {
585
	private IType findSecondaryType(String packageName, String typeName, IJavaProject project, boolean waitForIndexes, IProgressMonitor monitor) {
586
		if (JavaModelManager.VERBOSE) {
587
			Util.verbose("NameLookup FIND SECONDARY TYPES:"); //$NON-NLS-1$
588
			Util.verbose(" -> pkg name: " + packageName);  //$NON-NLS-1$
589
			Util.verbose(" -> type name: " + typeName);  //$NON-NLS-1$
590
			Util.verbose(" -> project: "+project.getElementName()); //$NON-NLS-1$
591
		}
592
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
586
		JavaModelManager manager = JavaModelManager.getJavaModelManager();
593
		try {
587
		try {
594
			IJavaProject javaProject = project;
588
			IJavaProject javaProject = project;
Lines 599-604 Link Here
599
					IType type = (IType) types.get(typeName);
593
					IType type = (IType) types.get(typeName);
600
					if (type != null) {
594
					if (type != null) {
601
						if (JavaModelManager.VERBOSE) {
595
						if (JavaModelManager.VERBOSE) {
596
							Util.verbose("NameLookup FIND SECONDARY TYPES:"); //$NON-NLS-1$
597
							Util.verbose(" -> pkg name: " + packageName);  //$NON-NLS-1$
598
							Util.verbose(" -> type name: " + typeName);  //$NON-NLS-1$
599
							Util.verbose(" -> project: "+project.getElementName()); //$NON-NLS-1$
602
							Util.verbose(" -> type: " + type.getElementName());  //$NON-NLS-1$
600
							Util.verbose(" -> type: " + type.getElementName());  //$NON-NLS-1$
603
						}
601
						}
604
						return type;
602
						return type;
(-)src/org/eclipse/jdt/core/tests/model/ClassNameTests.java (+46 lines)
Lines 16-21 Link Here
16
import org.eclipse.core.runtime.CoreException;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.core.runtime.IProgressMonitor;
18
import org.eclipse.core.runtime.NullProgressMonitor;
18
import org.eclipse.core.runtime.NullProgressMonitor;
19
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.core.runtime.content.IContentType;
19
import org.eclipse.jdt.core.IClasspathEntry;
21
import org.eclipse.jdt.core.IClasspathEntry;
20
import org.eclipse.jdt.core.ICompilationUnit;
22
import org.eclipse.jdt.core.ICompilationUnit;
21
import org.eclipse.jdt.core.IJavaProject;
23
import org.eclipse.jdt.core.IJavaProject;
Lines 1244-1247 Link Here
1244
		deleteProject("P");
1246
		deleteProject("P");
1245
	}
1247
	}
1246
}
1248
}
1249
1250
/**
1251
 * @bug 302455: java.lang.ClassCastException in secondary types removal
1252
 * @test Ensure that no invalid entries are put in the secondary types caches
1253
 * 		when a file extension spec is removed from the workspace as the CCE
1254
 * 		does no longer occur...
1255
 * 		Also verify that secondary types from the removed file extension are not
1256
 * 		kept in the projects caches as the secondary type is no longer in the
1257
 * 		cache at the end of the test...
1258
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=302455"
1259
 */
1260
public void testBug302455() throws CoreException, InterruptedException {
1261
	IContentType javaContentType = Platform.getContentTypeManager().getContentType(JavaCore.JAVA_SOURCE_CONTENT_TYPE);
1262
	try {
1263
		// Create project and file
1264
		assertNotNull("We should have got a Java Source content type!", javaContentType);
1265
		javaContentType.addFileSpec("b302455", IContentType.FILE_EXTENSION_SPEC);
1266
		IJavaProject javaProject = createJavaProject("P");
1267
		createFolder("/P/p");			
1268
		String filePath = "/P/p/Bug.b302455";
1269
		createFile(
1270
			filePath,
1271
			"package p;\n" +
1272
			"public class Bug {}\n" +
1273
			"class Secondary {}\n" +
1274
			""
1275
		);
1276
		waitUntilIndexesReady();
1277
		
1278
		// Get the secondary type
1279
		IType type = javaProject.findType("p.Secondary", new NullProgressMonitor());
1280
		assertNotNull("We should have found the secondary type!", type);
1281
		
1282
		// Remove file extension
1283
		org.eclipse.jdt.internal.core.JavaModelManager.VERBOSE = true;
1284
		javaContentType.removeFileSpec("b302455", IContentType.FILE_EXTENSION_SPEC);
1285
		
1286
		// As there's no specific event fo
1287
		type = javaProject.findType("p.Secondary", new NullProgressMonitor());
1288
		assertNull("We should have not found the secondary type!", type);
1289
	} finally {
1290
		deleteProject("P");
1291
	}
1292
}
1247
}
1293
}

Return to bug 302455