Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 482663

Summary: Infinite loop in JDT completion parser recovery/resume
Product: [Eclipse Project] JDT Reporter: i AqD <iiiaqd>
Component: CoreAssignee: Stephan Herrmann <stephan.herrmann>
Status: VERIFIED DUPLICATE QA Contact:
Severity: normal    
Priority: P3 CC: gayanper, jarthana, mauromol, stephan.herrmann
Version: 4.5.1   
Target Milestone: 4.20 M3   
Hardware: PC   
OS: All   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=535743
https://bugs.eclipse.org/bugs/show_bug.cgi?id=542574
https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/180903
https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=f405e82c76aed68376e8e17e0ebf3b01f613d19e
Whiteboard:
Attachments:
Description Flags
point mouse to "Date" to trigger the infinite loop in CompletionParser none

Description i AqD CLA 2015-11-20 05:12:11 EST
Created attachment 258174 [details]
point mouse to "Date" to trigger the infinite loop in CompletionParser

The recovery/resume in CompletionParser could stuck under certain circumstances and fail to quit.

The attached example is one of them: the bug is not that JDT fails to parse code but unable to stop attempting recovery and thus freeze the entire program.

It triggers the following code:

org.eclipse.jdt.internal.compiler.parser.Parser:parse() on a CompletionParser instance:

	switch (resumeOnSyntaxError()) {
		case HALT:
			......
			break;
		case RESTART:
			......
			continue ProcessTerminals;
		case RESUME:
			......
			continue ProcessTerminals;
	}

Thus I assume the job of stopping repeated resuming failures is on resumeOnSyntaxError(), unfortunately it does not do that in the case of CompletionParser:

org.eclipse.jdt.internal.codeassist.complete.CompletionParser:resumeOnSyntaxError():

	if (this.monitor != null) {
		if (++this.resumeOnSyntaxError > 100) {
			this.resumeOnSyntaxError = 0;
			if (this.monitor.isCanceled())
				return HALT;
		}
	}
	super.resumeOnSyntaxError();


Its super method, the Parser:resumeOnSyntaxError, never returns HALT unless there is a syntax error, while the CompletionParser:resumeOnSyntaxError cannot stop itself (by returning HALT) unless a monitor is used - but monitor is never used in CompletionParser:updateRecoveryState -> CompletionParser:createSnapShotParser cycle which seems to have something to do with lambda.


The solution seems easy, just returning HALT once resumeOnSyntaxError hits 100 whether there is monitor or not.
Comment 1 Eclipse Genie CLA 2018-09-20 03:44:09 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Stephan Herrmann CLA 2018-09-20 08:15:57 EDT
Problem still exists, just that code area is very fragile, and nobody has yet found the time to closely investigate.
Comment 3 Stephan Herrmann CLA 2018-10-19 18:38:29 EDT
Re-testing after bug 535743 I no longer see an endless loop, which is plausible, since the CompletionParser:createSnapShotParser() business has been reworked.

Instead, I see the invocation *with* a monitor hitting the threshold leading to a HALT. Still we get the dialog that completion took too long, and the parse tree is still insufficient for creating any proposals.

This still isn't perfect, but no longer a major problem
Comment 4 Eclipse Genie CLA 2020-12-04 16:14:07 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 5 Stephan Herrmann CLA 2021-05-22 07:13:27 EDT
Retesting on today's HEAD the situation has further improved: recovery no longer loops infinitely nor triggers the threshold.

Still we don't get any completions. 

@Gayan, would you like to give it a try (for 4.21)?

I don't recall specific treatment for type arguments in recent fixes, so perhaps this was a blind spot in bug 539685 and vicinity?
Comment 6 Stephan Herrmann CLA 2021-05-22 07:18:23 EDT
I spoke too soon. I have a JUnit that fails, BUT in a runtime workbench, we *do* get completions. I'll try to fix my JUnit which would then close this issue :)
Comment 7 Eclipse Genie CLA 2021-05-22 08:15:06 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/180903
Comment 9 Stephan Herrmann CLA 2021-05-22 13:33:21 EDT
(In reply to Eclipse Genie from comment #8)
> Gerrit change https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/180903 was
> merged to [master].
> Commit:
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=f405e82c76aed68376e8e17e0ebf3b01f613d19e

Passing test has been released, no code changes, which makes this a duplicate of bug 539685.

*** This bug has been marked as a duplicate of bug 539685 ***
Comment 10 Jay Arthanareeswaran CLA 2021-05-26 03:00:10 EDT
Verified for 4.20 RC1 with build I20210525-1800