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

Collapse All | Expand All

(-)search/org/eclipse/jdt/internal/core/search/matching/PossibleMatch.java (-2 / +4 lines)
Lines 68-75 Link Here
68
			if (fileName == NO_SOURCE_FILE_NAME) return CharOperation.NO_CHAR;
68
			if (fileName == NO_SOURCE_FILE_NAME) return CharOperation.NO_CHAR;
69
	
69
	
70
			SourceMapper sourceMapper = this.openable.getSourceMapper();
70
			SourceMapper sourceMapper = this.openable.getSourceMapper();
71
			IType type = ((ClassFile) this.openable).getType();
71
			if (sourceMapper != null) {
72
			contents = sourceMapper.findSource(type, fileName);
72
				IType type = ((ClassFile) this.openable).getType();
73
				contents = sourceMapper.findSource(type, fileName);
74
			}
73
		} else {
75
		} else {
74
			contents = this.document.getCharContents();
76
			contents = this.document.getCharContents();
75
		}
77
		}
(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+74 lines)
Lines 10189-10194 Link Here
10189
}
10189
}
10190
10190
10191
/**
10191
/**
10192
 * @bug 261722: [search] NPE after removing a project
10193
 * @test Ensure that no NPE occurs when project is deleted before the end of the search request
10194
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=261722"
10195
 */
10196
public void testBug261722() throws Exception {
10197
	IPath projectPath = null;
10198
	IJavaProject javaProject = null;
10199
	try {
10200
		// Create jar and project
10201
		final int MAX = 10;
10202
		final String[] pathsAndContents = new String[(1+MAX)*2];
10203
		pathsAndContents[0] = "p261722/X.java";
10204
		pathsAndContents[1] = "package p261722;\n" +
10205
        	"public class X {}";
10206
		for (int i=1; i<=MAX; i++) {
10207
			String className = (i<10) ? "X0"+i : "X"+i;
10208
			pathsAndContents[i*2] = "p261722/"+className+".java";
10209
			pathsAndContents[i*2+1] = "package p261722;\n" +
10210
	        	"public class "+className+" extends X {}";
10211
        }
10212
		javaProject = createJavaProject("P");
10213
		projectPath = javaProject.getProject().getLocation();
10214
		addLibrary(javaProject, "lib261722.jar", "lib261722.zip", pathsAndContents, "1.4");
10215
		waitUntilIndexesReady();
10216
		
10217
		// Search in separated thread
10218
		class TestSearchRequestor extends SearchRequestor {
10219
			int count = 0;
10220
			public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException {
10221
			    try {
10222
	                Thread.sleep(100);
10223
                } catch (InterruptedException e) {
10224
	                // skip
10225
                }
10226
                this.count++;
10227
		    }
10228
		}
10229
		final TestSearchRequestor requestor = new TestSearchRequestor();
10230
		final SearchPattern pattern = SearchPattern.createPattern("X*", IJavaSearchConstants.DECLARATIONS, IJavaSearchConstants.TYPE, SearchPattern.R_PATTERN_MATCH);
10231
		final IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
10232
		Runnable search = new Runnable() {
10233
			public void run() {
10234
				try {
10235
					new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null);
10236
				} catch (CoreException e) {
10237
					throw new RuntimeException(e);
10238
				}
10239
		    }
10240
		};
10241
		Thread thread = new Thread(search);
10242
		thread.start();
10243
10244
		// Delete project in current thread
10245
		while (requestor.count < (MAX/3)) {
10246
			Thread.sleep(10);
10247
		}
10248
		deleteProject(javaProject);
10249
		
10250
		// Wait until search is finished
10251
		while (thread.isAlive()) {
10252
			Thread.sleep(100);
10253
		}
10254
		
10255
		// Verify search results
10256
		assertEquals("Unexpected matches count", MAX+1, requestor.count);
10257
	} finally {
10258
		if (projectPath != null) {
10259
			deleteFile("/P/lib261722.jar");
10260
			deleteFile("/P/lib261722.zip");
10261
		}
10262
	}
10263
}
10264
10265
/**
10192
 * @bug 266582: [search] NPE finding references 
10266
 * @bug 266582: [search] NPE finding references 
10193
 * @test Ensure that no NPE occurs when searching for type references
10267
 * @test Ensure that no NPE occurs when searching for type references
10194
 * 	in a project which has the same jar twice on its classpath
10268
 * 	in a project which has the same jar twice on its classpath

Return to bug 261722