### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/CompletionTests2.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests2.java,v retrieving revision 1.47 diff -u -r1.47 CompletionTests2.java --- src/org/eclipse/jdt/core/tests/model/CompletionTests2.java 20 May 2009 14:37:06 -0000 1.47 +++ src/org/eclipse/jdt/core/tests/model/CompletionTests2.java 7 Jul 2009 09:38:09 -0000 @@ -5144,4 +5144,49 @@ JavaCore.setOptions(oldOptions); } } +//https://bugs.eclipse.org/bugs/show_bug.cgi?id=281598 +public void testBug281598() throws Exception { + + try { + // Create project and jar + IJavaProject p = createJavaProject("P", new String[] {"src"}, new String[]{"JCL_LIB", "/P/empty.jar"}, "bin"); + createFile("/P/empty.jar", ""); + refresh(p); + waitUntilIndexesReady(); + + // Create working copy + this.workingCopies = new ICompilationUnit[1]; + this.workingCopies[0] = getWorkingCopy( + "/P/src/test/Test.java", + "package test;"+ + "public class Test {\n" + + " void foo() {\n" + + " sys\n" + + " }\n" + + "}"); + + // do completion + CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, false, true, true); + requestor.allowAllRequiredProposals(); + NullProgressMonitor monitor = new NullProgressMonitor() { + long start = System.currentTimeMillis(); + + public boolean isCanceled() { + long time = System.currentTimeMillis() - this.start; + return time > 1000; // cancel after 1 sec + } + + }; + + String str = this.workingCopies[0].getSource(); + String completeBehind = "sys"; + int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length(); + this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner, monitor); + + // no results expected, just verify that no cancel operation exception occurs... + assertResults("", requestor.getResults()); + } finally { + deleteProject("P"); + } +} } #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/SearchableEnvironment.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/SearchableEnvironment.java,v retrieving revision 1.76 diff -u -r1.76 SearchableEnvironment.java --- model/org/eclipse/jdt/internal/core/SearchableEnvironment.java 4 Mar 2009 09:31:08 -0000 1.76 +++ model/org/eclipse/jdt/internal/core/SearchableEnvironment.java 7 Jul 2009 09:38:10 -0000 @@ -25,6 +25,7 @@ import org.eclipse.jdt.internal.core.search.BasicSearchEngine; import org.eclipse.jdt.internal.core.search.IRestrictedAccessConstructorRequestor; import org.eclipse.jdt.internal.core.search.IRestrictedAccessTypeRequestor; +import org.eclipse.jdt.internal.core.search.indexing.IndexManager; import org.eclipse.jdt.internal.core.util.Util; /** @@ -407,31 +408,27 @@ int matchRule = SearchPattern.R_PREFIX_MATCH; if (camelCaseMatch) matchRule |= SearchPattern.R_CAMELCASE_MATCH; if (monitor != null) { - found : while (true) { //the loop will finish if the search request ends or is cancelled + IndexManager indexManager = JavaModelManager.getIndexManager(); + while (indexManager.awaitingJobsCount() > 0) { try { - new BasicSearchEngine(this.workingCopies).searchAllTypeNames( - qualification, - SearchPattern.R_EXACT_MATCH, - simpleName, - matchRule, // not case sensitive - searchFor, - getSearchScope(), - typeRequestor, - CANCEL_IF_NOT_READY_TO_SEARCH, - progressMonitor); - break found; - } catch (OperationCanceledException e) { - if (monitor.isCanceled()) { - throw e; - } else { - try { - Thread.sleep(50); // indexes are not ready. sleep 50ms and retry the search request - } catch (InterruptedException e1) { - // Do nothing - } - } + Thread.sleep(50); // indexes are not ready. sleep 50ms and retry the search request + } catch (InterruptedException e) { + // Do nothing + } + if (monitor.isCanceled()) { + throw new OperationCanceledException(); } } + new BasicSearchEngine(this.workingCopies).searchAllTypeNames( + qualification, + SearchPattern.R_EXACT_MATCH, + simpleName, + matchRule, // not case sensitive + searchFor, + getSearchScope(), + typeRequestor, + FORCE_IMMEDIATE_SEARCH, + progressMonitor); } else { try { new BasicSearchEngine(this.workingCopies).searchAllTypeNames(