Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 154957 Details for
Bug 293861
Problem with refactoring when existing jar with invalid package names
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
patch.txt (text/plain), 7.04 KB, created by
Satyam Kandula
on 2009-12-23 03:06:51 EST
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Satyam Kandula
Created:
2009-12-23 03:06:51 EST
Size:
7.04 KB
patch
obsolete
>### 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 23 Dec 2009 06:49:48 -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 >@@ -22,9 +22,14 @@ > import org.eclipse.core.runtime.IPath; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.Path; >+import org.eclipse.jdt.core.compiler.CharOperation; >+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.Util; > import org.eclipse.jdt.internal.core.JavaModelManager; >@@ -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,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) >+ || 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 +203,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); >@@ -235,4 +246,28 @@ > public String toString() { > return "indexing " + this.containerPath.toString(); //$NON-NLS-1$ > } >+ >+ private boolean isValidPackageNameForClass(String className) { >+ char[] classNameArray = className.toCharArray(); >+ int start = 0; >+ int end; >+ if (this.scanner == null) >+ this.scanner = new Scanner(false /* comment */, true /* whitespace */, false /* nls */, >+ ClassFileConstants.JDK1_5/* sourceLevel */, null/* taskTag */, null/* taskPriorities */, true /* taskCaseSensitive */); >+ this.scanner.setSource(classNameArray); >+ // all the folders should be valid java names and the class name need not be validated >+ while ((end = CharOperation.indexOf('/', classNameArray, start)) != -1) { >+ this.scanner.startPosition = this.scanner.currentPosition = start; >+ this.scanner.eofPosition = end; >+ start = end +1; >+ try { >+ if (this.scanner.scanIdentifier() != TerminalTokens.TokenNameIdentifier || >+ this.scanner.currentPosition != this.scanner.eofPosition) >+ return false; >+ } catch (InvalidInputException e) { >+ return false; >+ } >+ } >+ return true; >+ } > } >#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 23 Dec 2009 06:49:58 -0000 >@@ -11070,4 +11070,49 @@ > 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"); >+ } >+} >+ > } >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 293861
:
151012
|
151013
|
151410
|
152146
|
153222
|
153223
|
154621
|
154622
|
154957
|
155298
|
155299
|
155300
|
158473
|
158478
|
159164
|
180736
|
180737
|
180738
|
180739