View | Details | Raw Unified | Return to bug 293861 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/util/Util.java (-1 / +17 lines)
Lines 1720-1726 Link Here
1720
	public static boolean isValidFolderNameForPackage(String folderName, String sourceLevel, String complianceLevel) {
1720
	public static boolean isValidFolderNameForPackage(String folderName, String sourceLevel, String complianceLevel) {
1721
		return JavaConventions.validateIdentifier(folderName, sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
1721
		return JavaConventions.validateIdentifier(folderName, sourceLevel, complianceLevel).getSeverity() != IStatus.ERROR;
1722
	}
1722
	}
1723
1723
	
1724
	/**
1725
	 * Returns true if the given class name has a valid package name
1726
	 * false if it is not.
1727
	 * @param className the name of the fully qualified class name separated by '/'
1728
	 * @param sourceLevel the source level
1729
	 * @param complianceLevel the compliance level
1730
	 */
1731
	public static boolean isPackageNameForClassValid(String className, String sourceLevel, String complianceLevel) {
1732
		String[] pkgName= splitOn('/', className, 0, className.length());
1733
		for (int i = 0, length = pkgName.length-1; i < length; i++) { // class name need not be verified
1734
			if (JavaConventions.validateIdentifier(pkgName[i], sourceLevel, complianceLevel).getSeverity() == IStatus.ERROR)
1735
				return false;
1736
		}
1737
		return true;
1738
			
1739
	}
1724
	/**
1740
	/**
1725
	 * Returns true if the given method signature is valid,
1741
	 * Returns true if the given method signature is valid,
1726
	 * false if it is not.
1742
	 * false if it is not.
(-)search/org/eclipse/jdt/internal/core/search/indexing/AddJarFileToIndex.java (-3 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 25-30 Link Here
25
import org.eclipse.jdt.core.search.IJavaSearchScope;
25
import org.eclipse.jdt.core.search.IJavaSearchScope;
26
import org.eclipse.jdt.core.search.SearchEngine;
26
import org.eclipse.jdt.core.search.SearchEngine;
27
import org.eclipse.jdt.core.search.SearchParticipant;
27
import org.eclipse.jdt.core.search.SearchParticipant;
28
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
28
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
29
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable;
29
import org.eclipse.jdt.internal.compiler.util.Util;
30
import org.eclipse.jdt.internal.compiler.util.Util;
30
import org.eclipse.jdt.internal.core.JavaModelManager;
31
import org.eclipse.jdt.internal.core.JavaModelManager;
Lines 153-159 Link Here
153
						// iterate each entry to index it
154
						// iterate each entry to index it
154
						ZipEntry ze = (ZipEntry) e.nextElement();
155
						ZipEntry ze = (ZipEntry) e.nextElement();
155
						String zipEntryName = ze.getName();
156
						String zipEntryName = ze.getName();
156
						if (Util.isClassFileName(zipEntryName))
157
						if (Util.isClassFileName(zipEntryName) && (indexedFileNames.get(zipEntryName) != null)
158
								|| org.eclipse.jdt.internal.core.util.Util.isPackageNameForClassValid(zipEntryName, CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5))
159
								// the class file may not be there if the package name is not valid
157
							indexedFileNames.put(zipEntryName, EXISTS);
160
							indexedFileNames.put(zipEntryName, EXISTS);
158
					}
161
					}
159
					boolean needToReindex = indexedFileNames.elementSize != max; // a new file was added
162
					boolean needToReindex = indexedFileNames.elementSize != max; // a new file was added
Lines 195-201 Link Here
195
198
196
					// iterate each entry to index it
199
					// iterate each entry to index it
197
					ZipEntry ze = (ZipEntry) e.nextElement();
200
					ZipEntry ze = (ZipEntry) e.nextElement();
198
					if (Util.isClassFileName(ze.getName())) {
201
					String zipEntryName = ze.getName();
202
					if (Util.isClassFileName(zipEntryName) && 
203
							org.eclipse.jdt.internal.core.util.Util.isPackageNameForClassValid(zipEntryName, CompilerOptions.VERSION_1_5, CompilerOptions.VERSION_1_5)) {
204
						// index only classes coming from valid packages - https://bugs.eclipse.org/bugs/show_bug.cgi?id=293861
199
						final byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
205
						final byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(ze, zip);
200
						JavaSearchDocument entryDocument = new JavaSearchDocument(ze, zipFilePath, classFileBytes, participant);
206
						JavaSearchDocument entryDocument = new JavaSearchDocument(ze, zipFilePath, classFileBytes, participant);
201
						this.manager.indexDocument(entryDocument, participant, index, this.containerPath);
207
						this.manager.indexDocument(entryDocument, participant, index, this.containerPath);
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+18 lines)
Lines 11026-11029 Link Here
11026
		deleteProject("P");
11026
		deleteProject("P");
11027
	}
11027
	}
11028
}
11028
}
11029
/**
11030
 * @bug 293861: Problem with refactoring when existing jar with invalid package names
11031
 * @test Ensure that the search doesn't return classes with invalid package names
11032
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=293861"
11033
 */
11034
public void testBug293861() throws CoreException {
11035
	try 
11036
	{
11037
		IJavaProject project = createJavaProject("P");
11038
		addClasspathEntry(project, JavaCore.newLibraryEntry(new Path("/JavaSearchBugs/lib/bug293861.jar"), null, null));
11039
		int mask = IJavaSearchScope.APPLICATION_LIBRARIES | IJavaSearchScope.SOURCES | IJavaSearchScope.REFERENCED_PROJECTS;
11040
		IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { project }, mask);
11041
		search("B", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, scope);
11042
		assertSearchResults("No search results expected", "", this.resultCollector);
11043
	} finally {
11044
		deleteProject("P");
11045
	}
11046
}
11029
}
11047
}

Return to bug 293861