### 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.454 diff -u -r1.454 JavaModelManager.java --- model/org/eclipse/jdt/internal/core/JavaModelManager.java 21 Jul 2010 14:13:46 -0000 1.454 +++ model/org/eclipse/jdt/internal/core/JavaModelManager.java 2 Sep 2010 03:46:35 -0000 @@ -997,9 +997,8 @@ JavaProjectElementInfo projectInfo = (JavaProjectElementInfo) getJavaModelManager().getInfo(project); ProjectCache projectCache = projectInfo == null ? null : projectInfo.projectCache; HashtableOfArrayToObject allPkgFragmentsCache = projectCache == null ? null : projectCache.allPkgFragmentsCache; - IClasspathEntry[] entries = - org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(resourcePath.lastSegment()) - ? project.getRawClasspath() // JAVA file can only live inside SRC folder (on the raw path) + boolean isJavaLike = org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(resourcePath.lastSegment()); + IClasspathEntry[] entries = isJavaLike ? project.getRawClasspath() // JAVA file can only live inside SRC folder (on the raw path) : ((JavaProject)project).getResolvedClasspath(); int length = entries.length; @@ -1011,6 +1010,8 @@ if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) continue; IPath rootPath = entry.getPath(); if (rootPath.equals(resourcePath)) { + if (isJavaLike) + return null; return project.getPackageFragmentRoot(resource); } else if (rootPath.isPrefixOf(resourcePath)) { // allow creation of package fragment if it contains a .java file that is included #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.215 diff -u -r1.215 ClasspathTests.java --- src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 27 May 2010 10:10:45 -0000 1.215 +++ src/org/eclipse/jdt/core/tests/model/ClasspathTests.java 2 Sep 2010 03:46:38 -0000 @@ -6747,5 +6747,26 @@ ContainerInitializer.setInitializer(null); } } +public void testBug321170() throws Exception { + try { + IJavaProject p = this.createJavaProject("P", new String[] {}, "bin"); + + IFile file = this.createFile("/P/bin/X.java", "public class X {}"); + + IClasspathEntry[] classpath = new IClasspathEntry[1]; + classpath[0] = JavaCore.newLibraryEntry(new Path("/P/bin/X.java"), null, null); + setClasspath(p, classpath); + ICompilationUnit element = (ICompilationUnit)JavaCore.create(file, p); + assertNotNull("File created", element); + } + catch(ClassCastException e){ + fail("classcast exception"); + } + finally { + deleteProject("P"); + ContainerInitializer.setInitializer(null); + } +} + }