### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core 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 5 Jan 2010 07:06:12 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -22,10 +22,15 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.compiler.InvalidInputException; 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.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.parser.Scanner; +import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; +import org.eclipse.jdt.internal.compiler.util.SuffixConstants; import org.eclipse.jdt.internal.compiler.util.Util; import org.eclipse.jdt.internal.core.JavaModelManager; import org.eclipse.jdt.internal.core.index.Index; @@ -36,6 +41,7 @@ private static final char JAR_SEPARATOR = IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR.charAt(0); IFile resource; + Scanner scanner; public AddJarFileToIndex(IFile resource, IndexManager manager) { super(resource.getFullPath(), manager); @@ -153,7 +159,8 @@ // iterate each entry to index it ZipEntry ze = (ZipEntry) e.nextElement(); String zipEntryName = ze.getName(); - if (Util.isClassFileName(zipEntryName)) + if (Util.isClassFileName(zipEntryName) && isValidPackageNameForClass(zipEntryName)) + // 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 +202,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) && + isValidPackageNameForClass(zipEntryName)) { + // 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); @@ -228,6 +238,30 @@ if (this.resource != null) return super.getJobFamily(); return this.containerPath.toOSString(); // external jar + } + private boolean isValidPackageNameForClass(String className) { + char[] classNameArray = className.toCharArray(); + if (this.scanner == null) + this.scanner = new Scanner(false /* comment */, true /* whitespace */, false /* nls */, + ClassFileConstants.JDK1_3/* sourceLevel */, null/* taskTag */, null/* taskPriorities */, true /* taskCaseSensitive */); + this.scanner.setSource(classNameArray); + this.scanner.eofPosition = classNameArray.length - SuffixConstants.SUFFIX_CLASS.length; + try { + if (this.scanner.scanIdentifier() == TerminalTokens.TokenNameIdentifier) { + while (this.scanner.eofPosition > this.scanner.currentPosition) { + if (this.scanner.getNextChar() != '/' || this.scanner.eofPosition <= this.scanner.currentPosition) { + return false; + } + if (this.scanner.scanIdentifier() != TerminalTokens.TokenNameIdentifier) { + return false; + } + } + return true; + } + } catch (InvalidInputException e) { + // invalid class name + } + return false; } protected Integer updatedIndexState() { return IndexManager.REBUILDING_STATE; #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.184 diff -u -r1.184 JavaSearchBugsTests.java --- src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 8 Dec 2009 11:34:01 -0000 1.184 +++ src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java 5 Jan 2010 07:06:35 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -11070,4 +11070,74 @@ removeClasspathEntry(JAVA_PROJECT, new Path(libPath)); } } +/** + * @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 testBug293861a() throws CoreException { + try + { + IJavaProject project = createJavaProject("P"); + addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b293861.jar"), null, null)); + int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); + + search("b293861TestFunc", IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS, scope); + assertSearchResults("No search results expected", "", this.resultCollector); + } finally { + deleteProject("P"); + } +} + +/* + * SearchEngine#searchAllTypeNames should also not return classes with invalid package names + */ +public void testBug293861b() throws CoreException { + try + { + IJavaProject project = createJavaProject("P"); + addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b293861.jar"), null, null)); + int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); + + TypeNameMatchCollector collector = new TypeNameMatchCollector(); + new SearchEngine().searchAllTypeNames( + null, + new char[][] {"b293861Test".toCharArray()}, + scope, + collector, + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null); + assertSearchResults("No search results expected", "", collector); + } finally { + deleteProject("P"); + } +} + +/* + * enum is a valid package name in Java1.4 and those classes should be returned by search + */ +public void testBug293861c() throws CoreException { + try + { + IJavaProject project = createJavaProject("P"); + addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/b293861.jar"), null, null)); + int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS; + IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask); + + TypeNameMatchCollector collector = new TypeNameMatchCollector(); + new SearchEngine().searchAllTypeNames( + null, + new char[][] {"InEnumPackage".toCharArray()}, + scope, + collector, + IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, + null); + assertSearchResults("Unexpected search results!", "InEnumPackage (not open) [in InEnumPackage.class [in enum [in /JavaSearchBugs/lib/b293861.jar [in P]]]]", collector); + } finally { + deleteProject("P"); + } +} + } \ No newline at end of file #P org.eclipse.jdt.core.tests.performance Index: src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceSearchTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceSearchTests.java,v retrieving revision 1.43 diff -u -r1.43 FullSourceWorkspaceSearchTests.java --- src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceSearchTests.java 27 Oct 2009 13:05:53 -0000 1.43 +++ src/org/eclipse/jdt/core/tests/performance/FullSourceWorkspaceSearchTests.java 5 Jan 2010 07:06:40 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -19,7 +19,6 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.IJavaElement; import org.eclipse.jdt.core.IPackageFragment; import org.eclipse.jdt.core.search.*; @@ -211,7 +210,7 @@ AbstractJavaModelTests.waitUntilIndexesReady(); // Remove project previous indexing - INDEX_MANAGER.removeIndexFamily(new Path("")); + INDEX_MANAGER.deleteIndexFiles(); INDEX_MANAGER.reset(); // Clean memory