Skip to content

Commit c1cccd3

Browse files
committed
CoreASTProvider: avoid Stackoverflow #1977
replaces tail recursion with infinite loop #1977
1 parent 31c8e0d commit c1cccd3

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

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

+22-22
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ 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;
61-
private CompilationUnit fAST;
62-
private Object fReconcileLock= new Object();
63-
private Object fWaitLock= new Object();
60+
private volatile ITypeRoot fActiveJavaElement;
61+
private volatile CompilationUnit fAST;
62+
private final Object fReconcileLock= new Object();
63+
private final Object fWaitLock= new Object();
6464
private volatile boolean fIsReconciling;
6565
private volatile Runnable fFinishReconciling;
6666

@@ -69,7 +69,7 @@ public final class CoreASTProvider {
6969
*/
7070
public static final class WAIT_FLAG {
7171

72-
private String fName;
72+
private final String fName;
7373

7474
private WAIT_FLAG(String name) {
7575
fName= name;
@@ -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)