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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java (+73 lines)
Lines 10425-10430 Link Here
10425
	}
10425
	}
10426
}
10426
}
10427
10427
10428
/**
10429
 * @bug 261722: [search] NPE after removing a project
10430
 * @test Ensure that no NPE occurs when project is deleted before the end of the search request
10431
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=261722"
10432
 */
10433
public void testBug261722() throws Exception {
10434
	IPath projectPath = null;
10435
	IJavaProject javaProject = null;
10436
	try {
10437
		// Create jar and project
10438
		final int MAX = 10;
10439
		final String[] pathsAndContents = new String[(1+MAX)*2];
10440
		pathsAndContents[0] = "p261722/X.java";
10441
		pathsAndContents[1] = "package p261722;\n" +
10442
        	"public class X {}";
10443
		for (int i=1; i<=MAX; i++) {
10444
			String className = (i<10) ? "X0"+i : "X"+i;
10445
			pathsAndContents[i*2] = "p261722/"+className+".java";
10446
			pathsAndContents[i*2+1] = "package p261722;\n" +
10447
	        	"public class "+className+" extends X {}";
10448
        }
10449
		javaProject = createJavaProject("P");
10450
		projectPath = javaProject.getProject().getLocation();
10451
		addLibrary(javaProject, "lib261722.jar", "lib261722.zip", pathsAndContents, "1.4");
10452
		waitUntilIndexesReady();
10453
		
10454
		// Search in separated thread
10455
		class TestSearchRequestor extends SearchRequestor {
10456
			int count = 0;
10457
			public void acceptSearchMatch(SearchMatch searchMatch) throws CoreException {
10458
			    try {
10459
	                Thread.sleep(100);
10460
                } catch (InterruptedException e) {
10461
	                // skip
10462
                }
10463
                this.count++;
10464
		    }
10465
		}
10466
		final TestSearchRequestor requestor = new TestSearchRequestor();
10467
		final SearchPattern pattern = SearchPattern.createPattern("X*", IJavaSearchConstants.DECLARATIONS, IJavaSearchConstants.TYPE, SearchPattern.R_PATTERN_MATCH);
10468
		final IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] { javaProject });
10469
		Runnable search = new Runnable() {
10470
			public void run() {
10471
				try {
10472
					new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null);
10473
				} catch (CoreException e) {
10474
					throw new RuntimeException(e);
10475
				}
10476
		    }
10477
		};
10478
		Thread thread = new Thread(search);
10479
		thread.start();
10480
10481
		// Delete project in current thread
10482
		while (requestor.count < (MAX/3)) {
10483
			Thread.sleep(10);
10484
		}
10485
		deleteProject(javaProject);
10486
		
10487
		// Wait until search is finished
10488
		while (thread.isAlive()) {
10489
			Thread.sleep(100);
10490
		}
10491
		
10492
		// Verify search results
10493
		assertEquals("Unexpected matches count", MAX+1, requestor.count);
10494
	} finally {
10495
		if (projectPath != null) {
10496
			deleteFile("/P/lib261722.jar");
10497
			deleteFile("/P/lib261722.zip");
10498
		}
10499
	}
10500
}
10428
10501
10429
/**
10502
/**
10430
 * @bug 265065: [search] java.lang.ClassCastException while running "Refactor...Extract Class"
10503
 * @bug 265065: [search] java.lang.ClassCastException while running "Refactor...Extract Class"
(-)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
		}

Return to bug 261722