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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/PackageFragment.java (-2 / +16 lines)
Lines 57-65 Link Here
57
57
58
	public String[] names;
58
	public String[] names;
59
59
60
	private static final short NOT_INITIALIZED = -1;
61
62
	private static final short VALID = 0;
63
64
	private static final short INVALID = 1;
65
66
	private short packageValid;
67
60
protected PackageFragment(PackageFragmentRoot root, String[] names) {
68
protected PackageFragment(PackageFragmentRoot root, String[] names) {
61
	super(root);
69
	super(root);
62
	this.names = names;
70
	this.names = names;
71
	this.packageValid = NOT_INITIALIZED;
63
}
72
}
64
/**
73
/**
65
 * @see Openable
74
 * @see Openable
Lines 390-403 Link Here
390
public boolean isDefaultPackage() {
399
public boolean isDefaultPackage() {
391
	return this.names.length == 0;
400
	return this.names.length == 0;
392
}
401
}
393
private boolean isValidPackageName() {
402
public boolean isValidPackageName() {
403
	if (this.packageValid != NOT_INITIALIZED) 
404
		return (this.packageValid == VALID);
394
	JavaProject javaProject = (JavaProject) getJavaProject();
405
	JavaProject javaProject = (JavaProject) getJavaProject();
395
	String sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
406
	String sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true);
396
	String complianceLevel = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
407
	String complianceLevel = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
397
	for (int i = 0, length = this.names.length; i < length; i++) {
408
	for (int i = 0, length = this.names.length; i < length; i++) {
398
		if (!Util.isValidFolderNameForPackage(this.names[i], sourceLevel, complianceLevel))
409
		if (!Util.isValidFolderNameForPackage(this.names[i], sourceLevel, complianceLevel)) {
410
			this.packageValid = INVALID;
399
			return false;
411
			return false;
412
		}	
400
	}
413
	}
414
	this.packageValid = VALID;
401
	return true;
415
	return true;
402
}
416
}
403
/**
417
/**
(-)search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java (-1 / +9 lines)
Lines 1173-1179 Link Here
1173
			} else {
1173
			} else {
1174
				openable = this.handleFactory.createOpenable(pathString, this.scope);
1174
				openable = this.handleFactory.createOpenable(pathString, this.scope);
1175
			}
1175
			}
1176
			if (openable == null) {
1176
			boolean valid = (openable != null);
1177
			// should not look for classes with invalid package names in jars 
1178
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=293861
1179
			if (valid && openable.getPackageFragmentRoot().isArchive()) {
1180
				IJavaElement element = openable.getParent();
1181
				if (element instanceof PackageFragment && !((PackageFragment)element).isValidPackageName())
1182
						valid = false;
1183
			}
1184
			if (!valid) {
1177
				if (this.progressMonitor != null) {
1185
				if (this.progressMonitor != null) {
1178
					this.progressWorked++;
1186
					this.progressWorked++;
1179
					if ((this.progressWorked%this.progressStep)==0) this.progressMonitor.worked(this.progressStep);
1187
					if ((this.progressWorked%this.progressStep)==0) this.progressMonitor.worked(this.progressStep);
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+20 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/b293861.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("testWithoutSource", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, scope);
11042
		assertSearchResults("No search results expected", "", this.resultCollector);
11043
		search("testWithSource", IJavaSearchConstants.TYPE, IJavaSearchConstants.DECLARATIONS, scope);
11044
		assertSearchResults("No search results expected", "", this.resultCollector);
11045
	} finally {
11046
		deleteProject("P");
11047
	}
11048
}
11029
}
11049
}

Return to bug 293861