### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/util/Util.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java,v retrieving revision 1.139 diff -u -r1.139 Util.java --- model/org/eclipse/jdt/internal/core/util/Util.java 12 Nov 2009 16:47:47 -0000 1.139 +++ model/org/eclipse/jdt/internal/core/util/Util.java 13 Nov 2009 11:51:18 -0000 @@ -1720,7 +1720,23 @@ public static boolean isValidFolderNameForPackage(String folderName, String sourceLevel, String complianceLevel) { return JavaConventions.validateIdentifier(folderName, sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR; } - + + /** + * Returns true if the given class name has a valid package name + * false if it is not. + * @param className the name of the fully qualified class name separated by '/' + * @param sourceLevel the source level + * @param complianceLevel the compliance level + */ + public static boolean isPackageNameForClassValid(String className, String sourceLevel, String complianceLevel) { + String[] pkgName= splitOn('/', className, 0, className.length()); + for (int i = 0, length = pkgName.length-1; i < length; i++) { // class name need not be verified + if (JavaConventions.validateIdentifier(pkgName[i], sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR) + return false; + } + return true; + + } /** * Returns true if the given method signature is valid, * false if it is not. Index: search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java,v retrieving revision 1.76 diff -u -r1.76 AddJarFileToIndex.java --- search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java 24 Nov 2008 15:57:41 -0000 1.76 +++ search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java 13 Nov 2009 11:51:18 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -25,6 +25,7 @@ import org.eclipse.jdt.core.search.IJavaSearchScope; import org.eclipse.jdt.core.search.SearchEngine; import org.eclipse.jdt.core.search.SearchParticipant; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; import org.eclipse.jdt.internal.compiler.util.Util; import org.eclipse.jdt.internal.core.JavaModelManager; @@ -153,7 +154,9 @@ // iterate each entry to index it ZipEntry ze = (ZipEntry) e.nextElement(); String zipEntryName = ze.getName(); - if (Util.isClassFileName(zipEntryName)) + if (Util.isClassFileName(zipEntryName) && (indexedFileNames.get(zipEntryName) != null) + || org.eclipse.jdt.internal.core.util.Util.isPackageNameForClassValid(zipEntryName, CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5)) + // the class file may not be there if the package name is not valid indexedFileNames.put(zipEntryName, EXISTS); } boolean needToReindex = indexedFileNames.elementSize != max; // a new file was added @@ -195,7 +198,10 @@ // iterate each entry to index it ZipEntry ze = (ZipEntry) e.nextElement(); - if (Util.isClassFileName(ze.getName())) { + String zipEntryName = ze.getName(); + if (Util.isClassFileName(zipEntryName) && + org.eclipse.jdt.internal.core.util.Util.isPackageNameForClassValid(zipEntryName, CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5)) { + // index only classes coming from valid packages - https://bugs.eclipse.org/bugs/show_bug.cgi?id=293861 final byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip); JavaSearchDocument entryDocument = new JavaSearchDocument(ze, zipFilePath, classFileBytes, participant); this.manager.indexDocument(entryDocument, participant, index, this.containerPath); #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java,v retrieving revision 1.180 diff -u -r1.180 JavaSearchBugsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 5 Nov 2009 15:11:51 -0000 1.180 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 13 Nov 2009 11:51:31 -0000 @@ -11026,4 +11026,22 @@ deleteProject("P"); } } +/** + * @bug 293861: Problem with refactoring when existing jar with invalid package names + * @test Ensure that the search doesn't return classes with invalid package names + * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=293861" + */ +public void testBug293861() throws CoreException { + try + { + IJavaProject project = createJavaProject("P"); + addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/bug293861.jar"), null, null)); + int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); + search("B", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, scope); + assertSearchResults("No search results expected", "", this.resultCollector); + } finally { + deleteProject("P"); + } +} } \ No newline at end of file