Bug 219855 - [1.5][compiler] StackOverflowError during: "Requesting Java AST from selection"
Summary: [1.5][compiler] StackOverflowError during: "Requesting Java AST from selection"
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.4 M7   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 225952 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-02-21 15:01 EST by Chris Paton CLA
Modified: 2008-04-28 11:20 EDT (History)
4 users (show)

See Also:


Attachments
Workspace .log file (101.81 KB, text/plain)
2008-02-21 15:01 EST, Chris Paton CLA
no flags Details
Exception stacktrace to stderr (561 bytes, text/plain)
2008-02-21 15:01 EST, Chris Paton CLA
no flags Details
Exception stacktrace to stderr (542 bytes, text/plain)
2008-02-21 15:02 EST, Chris Paton CLA
no flags Details
Fix as described by Kent in comment 7 (1007 bytes, patch)
2008-04-08 14:26 EDT, Chris Paton CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Paton CLA 2008-02-21 15:01:04 EST
Created attachment 90395 [details]
Workspace .log file

Build ID: I20080207-1530

I'm getting a StackOverflowError whilst working with a particular file "ManagePerformancesDialog" in the project that I'm working in. The error _only_ occurs when editing this file, which I've never had cause to open until now. Aside from being fairly long (8000 lines) I can't see anything particularly unusual with it.

When opening the file I get "Exception in thread "org.eclipse.jdt.internal.ui.text.JavaReconciler" java.lang.StackOverflowError" stacktrace to stderr [load.txt].

This is followed with a "Multiple Errors have Occurred" and "Internal Error" dialog warning me of the error and recommending I close the workbench. If I persist then the error re-occurs every 10 seconds or so as I click through the file. I've attached my .log file [log.txt] with the full details.

Also, if I hover over text in the file I get "Exception in thread "Text Viewer Hover Presenter" java.lang.StackOverflowError" to stderr [hover.txt]. This is preventable by turning off the hovers using the Java > Editor > Hovers preference.

I've checked out the latest org.eclipse.jdt.core soruce from CVS and the problem persists when running Eclipse with this. Both exceptions occur when org.eclipse.jdt.internal.compiler.lookup.FieldBinding.constant(FieldBinding.java:205) calls itself until the StackOverflowError kicks in. I had a go at debugging and the error is only raised when the code is dealing with a particular value for the originalField variable, which happens to be an enum constant. Bizzarely, the enum constant in particular and its declaring enum aren't even referenced by the file I'm working with.

I appreciate that this is likely to be hard/impossible to reproduce since I myself only get the issue with one file. Any suggestions folk can offer on how I can produce an isolated test case would be much appreciated. Similarly, if there's any other debug info you'd like to see or any other debugging steps that I should take then I'd be very happy to help.
Comment 1 Chris Paton CLA 2008-02-21 15:01:46 EST
Created attachment 90396 [details]
Exception stacktrace to stderr
Comment 2 Chris Paton CLA 2008-02-21 15:02:05 EST
Created attachment 90397 [details]
Exception stacktrace to stderr
Comment 3 Olivier Thomann CLA 2008-02-21 15:08:08 EST
Do you have a regression test for this ?
This could happen if the original field binding is equals to the current field binding.

Any idea, Kent ?
Comment 4 Olivier Thomann CLA 2008-02-21 15:08:47 EST
This the .log doesn't show the build id, could you please specify the build id?
Thanks.
Comment 5 Chris Paton CLA 2008-02-22 07:08:47 EST
Thanks for the quick response. I'm using 3.4M5. As per my original report this shows as I20080207-1530 in Help > About (I presume this is id you're looking for?). I had a copy of Eclipse 3.3 (I20070621-1340) lying around and the bug also occurs in this.

Had another look at things this morning (GMT). Oliver is correct that the problem only occurs when originalField == this. This makes sense because originalField = this.original() [line 195], and this.original() just returns this [line 342].

I've discovered that the problem doesn't occur all the time for the particular enum constant that's giving me grief: sometimes originalField.constant is non-null (a DoubleConstant with value NAN) which allows the recursive call to FieldBinding.constant() [line 205] to break out. It's when it's null that I get the infinite recursion.

Again, anything I can do to help just let me know.
Comment 6 Olivier Thomann CLA 2008-02-22 09:24:00 EST
If you could isolate the problem in a small test case with steps to reproduce, it would be really helpful.
Thanks for the build id. This is exactly what I was looking for.
Comment 7 Kent Johnson CLA 2008-03-26 14:36:27 EDT
Philippe - can we replace the recursive call in FieldBinding.constant() with

fieldConstant = originalField.constant == null ? Constant.NotAConstant : originalField.constant;

It passes all of our tests.
Comment 8 Philipe Mulet CLA 2008-03-26 16:25:10 EDT
This feels a good  change.
Comment 9 Kent Johnson CLA 2008-04-08 14:11:56 EDT
*** Bug 225952 has been marked as a duplicate of this bug. ***
Comment 10 Chris Paton CLA 2008-04-08 14:26:19 EDT
Created attachment 95246 [details]
Fix as described by Kent in comment 7

I wrote a patch (attached) as per Kent's suggestion in comment 7. I applied this to the code in HEAD and re-built the org.eclipse.jdt.core plugin.

I'm pleased to say that it fixed the bug in my case; I can now successfully edit and compile my problem file. I've been running the patch for a few days now and so far I've not seen any regressions caused by the change.

Thanks for the help!
Comment 11 Kent Johnson CLA 2008-04-14 14:05:56 EDT
Released into HEAD for 3.4M7
Comment 12 Philipe Mulet CLA 2008-04-16 07:56:57 EDT
Backported to 3.2 & 3.3 maintenance branches.
Comment 13 David Audel CLA 2008-04-28 11:20:54 EDT
Was verified for 3.4M7 by reporter (comment 10)