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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/IndexSelector.java (-5 / +7 lines)
Lines 194-207 Link Here
194
			char[][] focusQualifiedName = null;
194
			char[][] focusQualifiedName = null;
195
			if (isAutoBuilding && focus instanceof IJavaProject) {
195
			if (isAutoBuilding && focus instanceof IJavaProject) {
196
				IJavaElement javaElement = this.pattern.focus;
196
				IJavaElement javaElement = this.pattern.focus;
197
				while (javaElement != null && !(javaElement instanceof ICompilationUnit) && !(javaElement instanceof IClassFile)) {
197
				while (javaElement != null && !(javaElement instanceof ITypeRoot)) {
198
					javaElement = javaElement.getParent();
198
					javaElement = javaElement.getParent();
199
				}
199
				}
200
				if (javaElement != null) {
200
				if (javaElement != null) {
201
					ICompilationUnit compilationUnit = (ICompilationUnit) javaElement;
201
					IType primaryType = ((ITypeRoot) javaElement).findPrimaryType();
202
					char[][] qualifiedName = CharOperation.splitOn('.', compilationUnit.findPrimaryType().getFullyQualifiedName().toCharArray());
202
					if (primaryType != null) {
203
					char[][][] qualifiedNames = ReferenceCollection.internQualifiedNames(new char[][][] {qualifiedName});
203
						char[][] qualifiedName = CharOperation.splitOn('.', primaryType.getFullyQualifiedName().toCharArray());
204
					focusQualifiedName = qualifiedNames[0];
204
						char[][][] qualifiedNames = ReferenceCollection.internQualifiedNames(new char[][][] {qualifiedName});
205
						focusQualifiedName = qualifiedNames[0];
206
					}
205
				}
207
				}
206
			}
208
			}
207
209
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+80 lines)
Lines 23-28 Link Here
23
import org.eclipse.core.resources.IResourceChangeEvent;
23
import org.eclipse.core.resources.IResourceChangeEvent;
24
import org.eclipse.core.resources.IResourceChangeListener;
24
import org.eclipse.core.resources.IResourceChangeListener;
25
import org.eclipse.core.resources.IResourceDelta;
25
import org.eclipse.core.resources.IResourceDelta;
26
import org.eclipse.core.resources.IWorkspaceDescription;
26
import org.eclipse.core.resources.IncrementalProjectBuilder;
27
import org.eclipse.core.resources.IncrementalProjectBuilder;
27
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.IPath;
29
import org.eclipse.core.runtime.IPath;
Lines 11453-11456 Link Here
11453
	}	
11454
	}	
11454
}
11455
}
11455
11456
11457
/**
11458
 * @bug 304841: [search] NPE in IndexSelector.initializeIndexLocations
11459
 * @test Ensure that no NPE occurs when searching for a reference in a CU without primary type
11460
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304841"
11461
 */
11462
public void testBug304841() throws Exception {
11463
	boolean autoBuild = getWorkspace().isAutoBuilding();
11464
	IWorkspaceDescription preferences = getWorkspace().getDescription();
11465
	try {
11466
		// ensure that the workspace auto-build is ON
11467
		preferences.setAutoBuilding(true);
11468
		getWorkspace().setDescription(preferences);
11469
		
11470
		// create test case
11471
		IJavaProject project = createJavaProject("P");
11472
		createFolder("/P/p");
11473
		createFile(
11474
			"/P/p/Hello.java",
11475
			"package p;\n" + 
11476
			"class One {\n" + 
11477
			"}\n" + 
11478
			"class Two {\n" + 
11479
			"}\n"
11480
		);
11481
		createFile(
11482
			"/P/p/Ref.java",
11483
			"package p;\n" + 
11484
			"class Three {\n" + 
11485
			"	Two two;\n" + 
11486
			"}\n"
11487
		);
11488
		waitUntilIndexesReady();
11489
		
11490
		// perform search
11491
		final ICompilationUnit cu = getCompilationUnit("/P/p/Hello.java");
11492
		IType type = cu.getType("Two");
11493
		SearchPattern pattern = SearchPattern.createPattern(type, REFERENCES);
11494
		MatchLocator.setFocus(pattern, type);
11495
		new SearchEngine().search(
11496
			pattern,
11497
			new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
11498
			SearchEngine.createJavaSearchScope(new IJavaElement[] { project }),
11499
			this.resultCollector,
11500
			null
11501
		);
11502
		assertSearchResults(
11503
			"p/Ref.java p.Three.two [Two] EXACT_MATCH"
11504
		);
11505
	} finally {
11506
		preferences.setAutoBuilding(autoBuild);
11507
		getWorkspace().setDescription(preferences);
11508
		deleteProject("P");
11509
	}
11510
}
11511
public void testBug304841b() throws Exception {
11512
	boolean autoBuild = getWorkspace().isAutoBuilding();
11513
	IWorkspaceDescription preferences = getWorkspace().getDescription();
11514
	try {
11515
		// ensure that the workspace auto-build is ON
11516
		preferences.setAutoBuilding(true);
11517
		getWorkspace().setDescription(preferences);
11518
		
11519
		// perform search
11520
		IType type = getClassFile("/JavaSearchBugs/lib/Bug148380.class").getType();
11521
		SearchPattern pattern = SearchPattern.createPattern(type, REFERENCES);
11522
		MatchLocator.setFocus(pattern, type);
11523
		new SearchEngine().search(
11524
			pattern,
11525
			new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
11526
			getJavaSearchScope(),
11527
			this.resultCollector,
11528
			null
11529
		);
11530
		assertSearchResults(""); // No expected results, only verify that no CCE occurs
11531
	} finally {
11532
		preferences.setAutoBuilding(autoBuild);
11533
		getWorkspace().setDescription(preferences);
11534
	}
11535
}
11456
}
11536
}

Return to bug 304841