### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/NameLookupTests2.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/NameLookupTests2.java,v retrieving revision 1.26 diff -u -r1.26 NameLookupTests2.java --- src/org/eclipse/jdt/core/tests/model/NameLookupTests2.java 27 Jun 2008 16:02:40 -0000 1.26 +++ src/org/eclipse/jdt/core/tests/model/NameLookupTests2.java 20 Apr 2009 17:16:15 -0000 @@ -14,6 +14,7 @@ import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.*; @@ -250,6 +251,25 @@ } } /* + * Ensure that finding a package fragment with a path with a length equals to an external jar path length + 1 + * (regression test for bug 266771 NameLookup.findPackageFragment returns very incorrect package fragments) + */ +public void testFindPackageFragment2() throws CoreException { + try { + JavaProject project = (JavaProject)createJavaProject("P", new String[0], new String[] {"JCL_LIB"}, "bin"); + NameLookup nameLookup =getNameLookup(project); + IPath pathToSearch = new Path(getExternalJCLPathString() + 'a'); + IPackageFragment pkg = nameLookup.findPackageFragment(pathToSearch); + assertElementEquals( + "Unexpected package", + "", + pkg); + } finally { + deleteProject("P"); + } +} + +/* * Ensure that a member type with a name ending with a dollar and a number is found * (regression test for bug 103466 Stack Overflow: Requesting Java AST from selection) */ #P org.eclipse.jdt.core 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.125 diff -u -r1.125 NameLookup.java --- model/org/eclipse/jdt/internal/core/NameLookup.java 7 Mar 2009 00:58:57 -0000 1.125 +++ model/org/eclipse/jdt/internal/core/NameLookup.java 20 Apr 2009 17:16:17 -0000 @@ -414,8 +414,7 @@ continue; } IPath rootPath = root.getPath(); - int matchingCount = rootPath.matchingFirstSegments(path); - if (matchingCount != 0) { + if (rootPath.isPrefixOf(path)) { String name = path.toOSString(); // + 1 is for the File.separatorChar name = name.substring(rootPath.toOSString().length() + 1, name.length());