Skip to content

Commit b8ea18e

Browse files
author
Jörg Kubitz
committed
CoreASTProvider: avoid Stackoverflow #1977
replaces tail recursion with infinite loop #1977
1 parent e813d37 commit b8ea18e

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

org.eclipse.jdt.core.manipulation/common/org/eclipse/jdt/core/manipulation/CoreASTProvider.java

+18-18
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public final class CoreASTProvider {
5757
public static final String DEBUG_PREFIX= "ASTProvider > "; //$NON-NLS-1$
5858

5959
private volatile ITypeRoot fReconcilingJavaElement;
60-
private ITypeRoot fActiveJavaElement;
60+
private volatile ITypeRoot fActiveJavaElement;
6161
private CompilationUnit fAST;
6262
private Object fReconcileLock= new Object();
6363
private Object fWaitLock= new Object();
@@ -167,26 +167,26 @@ public CompilationUnit getAST(final ITypeRoot input, WAIT_FLAG waitFlag, IProgre
167167

168168
if (isReconciling) {
169169
try {
170-
notifyReconciler();
171-
// Wait for AST
172-
synchronized (fWaitLock) {
173-
if (isReconciling(input)) {
174-
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
175-
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "waiting for AST for: " + input.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$
176-
fWaitLock.wait(30000); // XXX: The 30 seconds timeout is an attempt to at least avoid a deadlock. See https://bugs.eclipse.org/366048#c21
170+
do {
171+
notifyReconciler();
172+
// Wait for AST
173+
synchronized (fWaitLock) {
174+
if (isReconciling(input)) {
175+
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
176+
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "waiting for AST for: " + input.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$
177+
fWaitLock.wait(3000); // XXX: The 3 seconds timeout is an attempt to at least avoid a deadlock. See https://bugs.eclipse.org/366048#c21
178+
}
177179
}
178-
}
179180

180-
// Check whether active element is still valid
181-
synchronized (this) {
182-
if (activeElement == fActiveJavaElement && fAST != null) {
183-
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
184-
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "...got AST: " + toString(fAST) + " for: " + input.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
185-
186-
return fAST;
181+
// Check whether active element is still valid
182+
synchronized (this) {
183+
if (activeElement == fActiveJavaElement && fAST != null) {
184+
if (JavaManipulationPlugin.DEBUG_AST_PROVIDER)
185+
System.out.println(getThreadName() + " - " + DEBUG_PREFIX + "...got AST: " + toString(fAST) + " for: " + input.getElementName()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
186+
return fAST;
187+
}
187188
}
188-
}
189-
return getAST(input, waitFlag, progressMonitor);
189+
} while (true); // notify and wait again
190190
} catch (InterruptedException e) {
191191
return null; // thread has been interrupted don't compute AST
192192
}

0 commit comments

Comments
 (0)