Skip to content

Commit

Permalink
[DOM based index] Prevent some deadlock
Browse files Browse the repository at this point in the history
Prevents from searching in index which index is being built.
  • Loading branch information
mickaelistria committed May 21, 2024
1 parent bf195ea commit 76187e1
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.compiler.CharOperation;
Expand Down Expand Up @@ -305,9 +304,11 @@ boolean indexDocumentFromDOM() {
try {
if (JavaProject.hasJavaNature(file.getProject())) {
IJavaProject javaProject = JavaCore.create(file.getProject());
IClasspathEntry cpEntry = javaProject.findContainingClasspathEntry(file);
IJavaElement element = javaProject.findElement(file.getFullPath().makeRelativeTo(cpEntry.getPath()));
if (element instanceof org.eclipse.jdt.internal.core.CompilationUnit modelUnit) {
// Do NOT call javaProject.getElement(pathToJavaFile) as it can loop inside index
// when there are multiple package root/source folders, and then cause deadlock
// so we go finer grain by picking the right fragment first (so index call shouldn't happen)
IPackageFragment fragment = javaProject.findPackageFragment(file.getFullPath().removeLastSegments(1));
if (fragment.getCompilationUnit(file.getName()) instanceof org.eclipse.jdt.internal.core.CompilationUnit modelUnit) {
// TODO check element info: if has AST and flags are set sufficiently, just reuse instead of rebuilding
ASTParser astParser = ASTParser.newParser(modelUnit.getElementInfo() instanceof ASTHolderCUInfo astHolder ? astHolder.astLevel : AST.getJLSLatest());
astParser.setSource(modelUnit);
Expand Down

0 comments on commit 76187e1

Please sign in to comment.