Bug 576914 - StackOverflowError in JavaModelManager.getArchiveValidity
Summary: StackOverflowError in JavaModelManager.getArchiveValidity
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.21   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 4.22 M3   Edit
Assignee: Jörg Kubitz CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
: 576849 (view as bug list)
Depends on:
Blocks:
 
Reported: 2021-10-27 06:57 EDT by Gunnar Wagenknecht CLA
Modified: 2021-12-03 06:25 EST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gunnar Wagenknecht CLA 2021-10-27 06:57:35 EDT
No steps to reproduce yet. This happens on 4.21. I suspect it's something with an archive on the classpath.


!ENTRY org.eclipse.core.jobs 4 2 2021-10-26 15:17:58.563
!MESSAGE An internal error occurred during: "Java Search".
!STACK 0
java.lang.StackOverflowError
	at java.base/java.util.HashMap.getNode(HashMap.java:567)
	at java.base/java.util.HashMap.get(HashMap.java:552)
	at org.eclipse.jdt.internal.core.JavaModelManager.getArchiveValidity(JavaModelManager.java:3392)
	at org.eclipse.jdt.internal.core.JavaModelManager.getArchiveValidity(JavaModelManager.java:3413)
	at org.eclipse.jdt.internal.core.JavaModelManager.getArchiveValidity(JavaModelManager.java:3413)
	at org.eclipse.jdt.internal.core.JavaModelManager.getArchiveValidity(JavaModelManager.java:3413)
...
Comment 1 Gunnar Wagenknecht CLA 2021-10-27 07:02:16 EDT
Looks like an issue in the code:
----
try {
  ZipFile zipFile = getZipFile(path, false);
  closeZipFile(zipFile);
  removeFromInvalidArchiveCache(path);
} catch (CoreException e) {
  // Archive is still invalid, fall through to reporting it is invalid.
}
// Retry the test from the start, now that we have an up-to-date result
return getArchiveValidity(path);
----

removeFromInvalidArchiveCache should probably be in a finally code block
Comment 2 Andrey Loskutov CLA 2021-10-27 07:37:39 EDT
(In reply to Gunnar Wagenknecht from comment #1)
> Looks like an issue in the code:
> ----
> try {
>   ZipFile zipFile = getZipFile(path, false);
>   closeZipFile(zipFile);
>   removeFromInvalidArchiveCache(path);
> } catch (CoreException e) {
>   // Archive is still invalid, fall through to reporting it is invalid.
> }
> // Retry the test from the start, now that we have an up-to-date result
> return getArchiveValidity(path);
> ----
> 
> removeFromInvalidArchiveCache should probably be in a finally code block

Looks like this is missing, or better addInvalidArchive() call.

The problem you see could be a regression from bug 571340, which touched code around this topic (but not exact this try/catch block).

If you could provide steps reproduce, would be nice, but beside this it looks like the getZipFile() throws CoreException trying to access the (out of date) archive and that invalid entry is never cleaned up or updated.
Comment 3 Jörg Kubitz CLA 2021-10-27 07:41:50 EDT
i faced it myself when debugging, standing at breakpoints for more then 2 min.
https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/184542
contains a solution.
Comment 4 Andrey Loskutov CLA 2021-10-27 07:57:41 EDT
(In reply to Jörg Kubitz from comment #3)
> i faced it myself when debugging, standing at breakpoints for more then 2
> min.
> https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/184542
> contains a solution.

While this could be a solution, this is a very big change, and I still haven't found time to review it, which most likely means, it is going to 4.23. For the time being, adding addInvalidArchive() call in the empty catch block would also suffice. I can push the patch if there is no better suggestion.
Comment 5 Jörg Kubitz CLA 2021-10-27 08:01:17 EDT
(In reply to Andrey Loskutov from comment #4)
> 4.23. For the time being, adding addInvalidArchive() call in the empty catch
> block would also suffice. I can push the patch if there is no better
> suggestion.

I am busy today, but i could extract the essential fix for this somewhen this week if wanted.
Comment 6 Eclipse Genie CLA 2021-10-28 06:03:53 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.core/+/187082
Comment 8 Manoj N Palat CLA 2021-11-11 08:03:35 EST
Verified for Eclipse Version: 2021-12 (4.22) M3 with Build id: I20211110-1800
[by code inspection]
Comment 9 Andrey Loskutov CLA 2021-12-03 06:25:47 EST
*** Bug 576849 has been marked as a duplicate of this bug. ***