Bug 548779 - [1.8][complete] eclipse hangs on String Autocompletion
Summary: [1.8][complete] eclipse hangs on String Autocompletion
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.11   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.20 M3   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-28 16:13 EDT by David Georg Reichelt CLA
Modified: 2021-05-26 01:05 EDT (History)
3 users (show)

See Also:


Attachments
Dump when the error appeared (34.61 KB, application/octet-stream)
2019-06-28 16:13 EDT, David Georg Reichelt CLA
no flags Details
Dump when the error appeared in eclipse 4.12 (35.31 KB, application/octet-stream)
2019-06-28 17:05 EDT, David Georg Reichelt CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Georg Reichelt CLA 2019-06-28 16:13:54 EDT
Created attachment 279119 [details]
Dump when the error appeared

I am running eclipse 2018-12 for developing maven and Gradle-Projects. Unforunately, since about an hour, eclipse hangs everytime when I try to use autocompletion on String variables. If I use autocompletion on other Classes, e.g. File, Set, or classes defined by me, everythings works fine.

In the eclipse.ini, I've set space to -Xmx2g. eclipse does not use this space; my system got 16 GB RAM and only 6 are used, so I assume it is not a memory error.

Deleting .metadata in the workspace did not solve the problem. If I switch to an empty workspace, create an empty Java project and one Test class in a test package, and enter this code:

package test;

public class Test {
	String val = "";
	{
//		val.match
	}
}

interface ConditionChecker {
	boolean check(String line);
}

enum MyGuesser {
	INT_LONG("INT_LONG", (line) -> {
		return line.contains("int");
	}, (line) -> {
		return line.contains("long");
	});

	String name;
	ConditionChecker checker;
	ConditionChecker checkerOld;

	MyGuesser(String name, ConditionChecker checker, ConditionChecker checkerOld) {
		this.name = name;
		this.checker = checker;
		this.checkerOld = checkerOld;
	}
}

The error appears. Seems like two of this interface instances need to be present - if only one is there, the error does not appear.

A thread dump is attached.
Comment 1 Andrey Loskutov CLA 2019-06-28 16:51:09 EDT
Please try Eclipse 4.13.
Comment 2 David Georg Reichelt CLA 2019-06-28 17:05:22 EDT
Created attachment 279120 [details]
Dump when the error appeared in eclipse 4.12

I've tried it with eclipse 4.12, so the current 2019-06 download. There, the same bug appears. Unfortunately, I can't find 4.13, could you maybe provide a download link?
Comment 3 Jay Arthanareeswaran CLA 2019-07-02 02:33:41 EDT
(In reply to David Georg Reichelt from comment #2)
> I've tried it with eclipse 4.12, so the current 2019-06 download. There, the
> same bug appears. Unfortunately, I can't find 4.13, could you maybe provide
> a download link?

There are no 4.13 releases yet. But the latest builds are listed under the Integration Builds section in

https://download.eclipse.org/eclipse/downloads/
Comment 4 Andrey Loskutov CLA 2019-07-03 09:23:08 EDT
I can reproduce on 4.13 master, trying to use autocomplete at line.| position

After some seconds I get an error dialog (not a full hang) saying the code complete was not able terminate timely, and error log for UI freeze with following stack:

	at org.eclipse.jdt.internal.compiler.parser.Scanner.<init>(Scanner.java:180)
	at org.eclipse.jdt.internal.compiler.parser.Scanner.<init>(Scanner.java:308)
	at org.eclipse.jdt.internal.codeassist.complete.CompletionScanner.<init>(CompletionScanner.java:62)
	at org.eclipse.jdt.internal.codeassist.complete.CompletionScanner.<init>(CompletionScanner.java:51)
	at org.eclipse.jdt.internal.codeassist.complete.CompletionJavadocParser.<init>(CompletionJavadocParser.java:62)
	at org.eclipse.jdt.internal.codeassist.complete.CompletionParser.createJavadocParser(CompletionParser.java:5740)
	at org.eclipse.jdt.internal.compiler.parser.Parser.<init>(Parser.java:980)
	at org.eclipse.jdt.internal.codeassist.impl.AssistParser.<init>(AssistParser.java:134)
	at org.eclipse.jdt.internal.codeassist.complete.CompletionParser.<init>(CompletionParser.java:190)
	at org.eclipse.jdt.internal.codeassist.complete.CompletionParser.createSnapShotParser(CompletionParser.java:5544)
	at org.eclipse.jdt.internal.codeassist.complete.CompletionParser.updateRecoveryState(CompletionParser.java:5701)
	at org.eclipse.jdt.internal.compiler.parser.Parser.resumeOnSyntaxError(Parser.java:13326)
	at org.eclipse.jdt.internal.codeassist.complete.CompletionParser.resumeOnSyntaxError(CompletionParser.java:5585)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:11906)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:12252)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:12209)
	at org.eclipse.jdt.internal.compiler.parser.Parser.dietParse(Parser.java:10617)
	at org.eclipse.jdt.internal.codeassist.complete.CompletionParser.dietParse(CompletionParser.java:5063)
	at org.eclipse.jdt.internal.codeassist.CompletionEngine.complete(CompletionEngine.java:2052)
	at org.eclipse.jdt.internal.core.Openable.codeComplete(Openable.java:136)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeComplete(CompilationUnit.java:368)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeComplete(CompilationUnit.java:358)
	at org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposalComputer.internalComputeCompletionProposals(JavaCompletionProposalComputer.java:253)
	at org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposalComputer.computeCompletionProposals(JavaCompletionProposalComputer.java:215)
	at org.eclipse.jdt.internal.ui.text.java.JavaTypeCompletionProposalComputer.computeCompletionProposals(JavaTypeCompletionProposalComputer.java:66)
	at org.eclipse.jdt.internal.ui.text.java.CompletionProposalComputerDescriptor.computeCompletionProposals(CompletionProposalComputerDescriptor.java:336)
	at org.eclipse.jdt.internal.ui.text.java.CompletionProposalCategory.computeCompletionProposals(CompletionProposalCategory.java:340)
	at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.collectProposals(ContentAssistProcessor.java:334)
	at org.eclipse.jdt.internal.ui.text.java.ContentAssistProcessor.computeCompletionProposals(ContentAssistProcessor.java:291)
	at org.eclipse.jface.text.contentassist.ContentAssistant$2.lambda$0(ContentAssistant.java:2015)
	at org.eclipse.jface.text.contentassist.ContentAssistant$2$$Lambda$1854/0x0000000840facc40.accept(Unknown Source)
Comment 5 Stephan Herrmann CLA 2019-07-03 17:10:43 EDT
Wow, it really seems to hang at this line:

//---
	public /*static*/ final char[][][][] charArray_length =
		new char[OptimizedLength][TableSize][InternalTableSize][];
//---

allocating an array of 7 x 30 x 6 chars.

(Needless to say that nothing relevant has changed here for ages).
Comment 6 Andrey Loskutov CLA 2019-07-03 17:12:49 EDT
(In reply to Stephan Herrmann from comment #5)
> Wow, it really seems to hang at this line:
> 
> //---
> 	public /*static*/ final char[][][][] charArray_length =
> 		new char[OptimizedLength][TableSize][InternalTableSize][];
> //---
> 
> allocating an array of 7 x 30 x 6 chars.
> 
> (Needless to say that nothing relevant has changed here for ages).

I guess there's a loop before?
Comment 7 Stephan Herrmann CLA 2019-07-03 17:20:29 EDT
After closing the error (timeout) popup I see an interesting message in the status line:

The constructor MyGuesser(String, (<no type> line)->{}, (<no type> line)->{}) is undefined.
Comment 8 Stephan Herrmann CLA 2019-07-03 17:21:50 EDT
(In reply to Andrey Loskutov from comment #6)
> (In reply to Stephan Herrmann from comment #5)
> > Wow, it really seems to hang at this line:
> > 
> > //---
> > 	public /*static*/ final char[][][][] charArray_length =
> > 		new char[OptimizedLength][TableSize][InternalTableSize][];
> > //---
> > 
> > allocating an array of 7 x 30 x 6 chars.
> > 
> > (Needless to say that nothing relevant has changed here for ages).
> 
> I guess there's a loop before?

No, its a field initializer. Or what you mean "before"?

Someone creating Scanners in a tight loop?
Comment 9 Andrey Loskutov CLA 2019-07-03 17:22:24 EDT
Yep.
Comment 10 Stephan Herrmann CLA 2019-07-03 17:24:25 EDT
Right, CompletionParser.createSnapShotParser() is invoked *many* times.
Comment 11 Stephan Herrmann CLA 2019-07-03 17:26:22 EDT
Still funny, that the innocent allocation is always on the stack top, when someone looks, given that we are still running through the non-trivial loop below in Parser.parse()
Comment 12 Stephan Herrmann CLA 2019-07-03 17:38:33 EDT
It's one of the dreaded syntax recovery scenarios for lambdas, which we don't have under control yet.

Interestingly, the current recovered element (RecoveredType) has a RecoveredField with this parse tree:

INT_LONG("INT_LONG", (<no type> line) -> {
  return <CompleteOnName:line.>;
  contains("int");
}, (<no type> line) -> {
  return line.contains("long");
}),

which doesn't look too bad, except that the second ctor arg is not semantically valid:

(<no type> line) -> {
  return <CompleteOnName:line.>;
  contains("int");
}

Just the parser doesn't make any progress.


Ah, it's not a total hang due to https://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=7dbc472feab6f8985cd72052d6eaace52c7ea562 "[1.8] Follow ups to bug 427322 and bug 425084"
Comment 13 Stephan Herrmann CLA 2019-07-03 17:46:35 EDT
Anyone looking at this bug may want to first have a look at https://wiki.eclipse.org/JDT_Core_Programmer_Guide/Completion - which is known to be incomplete, so completing (sic) that page is on our long term agenda.
Comment 14 Stephan Herrmann CLA 2019-07-03 17:49:25 EDT
And a quote from 2014:

(Stephan Herrmann from bug 425084 comment #2)
> CompletionParser does not seem to make any progress, with lots of snapshot
> parsers being created etc. ...
> Looks like the kind of magic that only Srikanth can master :)
Comment 15 Eclipse Genie CLA 2021-04-22 16:24:23 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/179694
Comment 16 Stephan Herrmann CLA 2021-04-22 16:26:10 EDT
(In reply to Eclipse Genie from comment #15)
> New Gerrit change created:
> https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/179694

adding a regression test from comment 0, which passes on HEAD, assumebly since the fix for bug 539685

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