Bug 571752 - Code completion on import throws StackOverflowError
Summary: Code completion on import throws StackOverflowError
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.18   Edit
Hardware: PC Unix All
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: needinfo
Depends on:
Blocks:
 
Reported: 2021-03-07 07:08 EST by Leon Hofmeister CLA
Modified: 2023-02-27 03:06 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Leon Hofmeister CLA 2021-03-07 07:08:22 EST
Description
-----------

When manually writing/ editing an import entry,
code completion not only fails but throws an StackOverflowError because of an endless recursion.
Even though this issue was reported as "Unix all" (seen in Ubuntu 18.04, Kubuntu 20.04, Arch 1.4), it is most likely that this issue exists on every OS.
This bug results in
a) no code completion
b) two annoying popups (one informing you of the error, one asking you the exit the workbench) - no repercussions could be observed if both get ignored

How to reproduce
----------------

1) Open a java file (unimportant if it is inside the default package or not, could be replicated with both)
2) type "import ja"
3) press "Ctrl+Enter" directly behind the ja
4) Enjoy ;)

Stacktrace
----------

java.lang.StackOverflowError
	at org.eclipse.jdt.internal.core.JavaElement.hashCode(JavaElement.java:548)
	at java.base/java.util.HashMap.hash(HashMap.java:340)
	at java.base/java.util.HashMap.getNode(HashMap.java:570)
	at java.base/java.util.HashMap.get(HashMap.java:558)
	at org.eclipse.jdt.internal.core.JavaModelCache.getInfo(JavaModelCache.java:158)
	at org.eclipse.jdt.internal.core.JavaModelManager.getInfo(JavaModelManager.java:2186)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:324)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:312)
	at org.eclipse.jdt.internal.core.AbstractModule.getModuleInfo(AbstractModule.java:83)
	at org.eclipse.jdt.internal.core.AbstractModule.getExportedPackages(AbstractModule.java:121)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.findPackagesFromRequires(SearchableEnvironment.java:297)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.findPackagesFromRequires(SearchableEnvironment.java:306)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.findPackagesFromRequires(SearchableEnvironment.java:306)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.findPackagesFromRequires(SearchableEnvironment.java:306)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.findPackagesFromRequires(SearchableEnvironment.java:306)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.findPackagesFromRequires(SearchableEnvironment.java:306)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.findPackagesFromRequires(SearchableEnvironment.java:306)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.findPackagesFromRequires(SearchableEnvironment.java:306)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.findPackagesFromRequires(SearchableEnvironment.java:306)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.findPackagesFromRequires(SearchableEnvironment.java:306)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.findPackagesFromRequires(SearchableEnvironment.java:306)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.findPackagesFromRequires(SearchableEnvironment.java:306)
        .
        .
        .
Comment 1 Andrey Loskutov CLA 2021-03-07 10:12:19 EST
Please provide exact Eclipse version, attach full error log and if possible, share sample project to reproduce. Please also try 4.19 RC2 build.
Comment 2 Leon Hofmeister CLA 2021-03-07 12:00:36 EST
I use Eclipse 20.12, and the error log gives exactly the stack trace pasted, except for more occurrences of
"at org.eclipse.jdt.internal.core.SearchableEnvironment.findPackagesFromRequires(SearchableEnvironment.java:306)".

The only additional info from the error log is
"!SESSION 2021-02-21 09:01:58.830 -----------------------------------------------
eclipse.buildId=4.18.0.I20201202-1800
java.version=15
java.vendor=AdoptOpenJDK
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments:  -product org.eclipse.epp.package.jee.product
Command-line arguments:  -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.jee.product"

I've tried reproducing the bug with a new sample project (a computer restart was between this try and the reported try), but surprisingly now not even the original buggy file could replicate the bug, only some minor annoyance could be achieved (see below).

I've tested whether changing the version of the project jdk changes something, but apparently it does not, except for one annoyance:
On jdks prior to Java 9 (I've tested until Java 6) everything works exactly as intended.
On jdks beginning from 9, the packages, which I would assume to be suggested first by code completion, (i.e. the package recommendation "java" after typing "import ja") is hidden behind several (sun/jdk).resources packages.

Considering the error log, it seems pretty clear that somehow an endless recursion got created that only occurs when certain (currently unknown) conditions are met.

So, to summarize:
This bug appears to be a non-deterministic endless recursion. The type of bug that developers hate most to fix.
Comment 3 Eclipse Genie CLA 2023-02-27 03:06:39 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.