Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 432541 - Stack Overflow in Java Search - type inference issue?
Summary: Stack Overflow in Java Search - type inference issue?
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 normal with 2 votes (vote)
Target Milestone: 4.4.1   Edit
Assignee: Manoj N Palat CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 434800 (view as bug list)
Depends on:
Blocks:
 
Reported: 2014-04-10 13:08 EDT by Philippe Marschall CLA
Modified: 2017-03-01 12:34 EST (History)
11 users (show)

See Also:
stephan.herrmann: review+


Attachments
Project to reproduce the issue (22.54 KB, application/zip)
2014-04-12 04:26 EDT, Philippe Marschall CLA
no flags Details
Modified org.eclipse.jdt.core.*.jar plugin (5.63 MB, application/octet-stream)
2014-04-18 05:37 EDT, Manoj N Palat CLA
no flags Details
Workspace to reproduce the issue (11.46 MB, application/zip)
2014-04-27 07:02 EDT, Philippe Marschall CLA
no flags Details
feature patch (7.78 MB, application/x-zip-compressed)
2014-04-30 10:57 EDT, Manoj N Palat CLA
no flags Details
Log after Manoj's feature patch (4.39 KB, text/plain)
2014-06-30 15:04 EDT, Georgian Grec CLA
no flags Details
Luna Feature Patch (4.94 MB, application/x-zip-compressed)
2014-07-01 10:05 EDT, Manoj N Palat CLA
no flags Details
Log after Manoj's second feature patch (1001.79 KB, text/plain)
2014-07-01 11:03 EDT, Georgian Grec CLA
no flags Details
Proposed Patch - WIP (6.88 KB, patch)
2014-07-07 12:18 EDT, Manoj N Palat CLA
no flags Details | Diff
Proposed Patch (6.99 KB, patch)
2014-07-08 04:27 EDT, Manoj N Palat CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Marschall CLA 2014-04-10 13:08:52 EDT
I have the following error in my error log

eclipse.buildId=4.4.0.I20140318-0830

An internal error occurred during: "Java Search".

java.lang.StackOverflowError
	at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.mentionsAny(ParameterizedTypeBinding.java:915)
	at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.mentionsAny(ParameterizedTypeBinding.java:915)
	at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.mentionsAny(ParameterizedTypeBinding.java:915)
	at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.mentionsAny(ParameterizedTypeBinding.java:915)
	at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.mentionsAny(ParameterizedTypeBinding.java:915)
	at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.mentionsAny(ParameterizedTypeBinding.java:915)
Comment 1 Philippe Marschall CLA 2014-04-10 13:11:53 EDT
It happens when I right click on a specific .java file in the package explorer and select References -> Project

The class looks like this


final class Constants {

  private Constants() {
    throw new AssertionError("not instantiable");
  }
  
  static final String PERSISTENCE_UNIT_NAME =  "persistence.unit.name";

}
Comment 2 Manoj N Palat CLA 2014-04-10 23:25:47 EDT
(In reply to Philippe Marschall from comment #1)
> 
> final class Constants {

Unable to reproduce with the given class; but that's because this issue is found at a ParameterizedTypeBinding. We would have to probably identify that expression.

Srikanth: Since this looks like a type inference issue, could you please take a look at this?
Comment 3 Philippe Marschall CLA 2014-04-12 04:26:54 EDT
Created attachment 241914 [details]
Project to reproduce the issue

A project to reproduce the issue. You need to have m2eclipse installed.

- Select "Constants.java" in the package explorer
- Right click -> References -> Project
Comment 4 Srikanth Sankaran CLA 2014-04-14 03:12:37 EDT
Manoj, Please take a look.
Comment 5 Stephan Herrmann CLA 2014-04-15 04:48:11 EDT
Manoj, you might have seen that classes like TypeVariableBinding have a flag inRecursiveFunction to avoid this kind of infinite recursion.

PTB doesn't have such a field, because we don't expect *directly* recursive PTB, recursion should only be possible via a TVB or WB (oops: WB.mentionsAny doesn't use its flag).
Comment 6 Manoj N Palat CLA 2014-04-18 05:37:21 EDT
Created attachment 242113 [details]
Modified org.eclipse.jdt.core.*.jar plugin

(In reply to Stephan Herrmann from comment #5)
> WB.mentionsAny doesn't use its flag).

Thanks a lot, Stephan. I am attaching the jdt.core.jar file with this modification incorporated for trying out.

Philippe: Local reproduction of the issue was not successful. However could you please use the attached org.eclipse.jdt.core.*.jar file instead of the current jar to check whether the problem exists with that file.
Comment 7 Philippe Marschall CLA 2014-04-22 14:26:34 EDT
This issue is still happening with the modified jar.
Comment 8 Manoj N Palat CLA 2014-04-23 05:47:49 EDT
(In reply to Philippe Marschall from comment #7)
>

Do you have any dependent jars for this project which you can share? If its big, you can share it privately as well to my email address.
Comment 9 Manoj N Palat CLA 2014-04-23 06:03:02 EDT
(In reply to Manoj Palat from comment #8)
> 
Philippe: Better still if you can do the following:

 - Create a new workspace with this project alone and reproduce the issue. And Please send/upload in bug  the entire workspace.
Comment 10 Manoj N Palat CLA 2014-04-24 22:51:23 EDT
Moving to 4.5
Comment 11 Philippe Marschall CLA 2014-04-27 07:02:05 EDT
Created attachment 242364 [details]
Workspace to reproduce the issue

To reproduce the issue:
 * you need to have Maven to download the third party JARs from Maven Central http://maven.apache.org/download.cgi#Installation
 * run the following command to download the third party JARs from Maven Central mvn dependency:resolve dependency:sources
 * select com.github.marschall.threeten.jpa.Constants.java in the src/test/java folder in the Package Explorer
 * right click -> References -> Project

$ java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
Comment 12 Srikanth Sankaran CLA 2014-04-28 02:02:55 EDT
Manoj, see if you are able to reproduce using the description in comment#11 and
if yes, evaluate a fix for 4.4. I am worried that this problem could show up 
outside the context of a search problem also.
Comment 13 Manoj N Palat CLA 2014-04-30 10:57:50 EDT
Created attachment 242549 [details]
feature patch

Could not reproduce locally. The PTB.java:915/mentionsAny() is not being hit even. 

Philippe:please apply the feature patch and check out the messages (prefixed by PTB) to get more info and paste the last few messages here.
Comment 14 Stephan Herrmann CLA 2014-05-13 15:32:40 EDT
*** Bug 434800 has been marked as a duplicate of this bug. ***
Comment 15 Georgian Grec CLA 2014-06-29 11:39:12 EDT
The problem is still reproducible even with the feature patch applied. I get the same StackOverflow when trying to build the entire workspace (which contains quite a few projects).

Projects become red saying "The project cannot be built until its prerequisite X is built.".

Reproducible with JDK 8 (05)
Works fine with JDK 7 (51)

Was this pushed to Mars? To me it looks like a blocker.
Comment 16 Stephan Herrmann CLA 2014-06-29 11:51:05 EDT
(In reply to Georgian Grec from comment #15)
> The problem is still reproducible even with the feature patch applied. I get
> the same StackOverflow when trying to build the entire workspace (which
> contains quite a few projects).

If I understand Manoj correctly, the feature patch does not contain a fix but implements additional logging to narrow down the problem.

(In reply to Manoj Palat from comment #13)
> Philippe:please apply the feature patch and check out the messages (prefixed
> by PTB) to get more info and paste the last few messages here.

Can you find any matching messages in your logs? If so please post here. TIA.
Comment 17 Georgian Grec CLA 2014-06-30 15:04:36 EDT
Created attachment 244678 [details]
Log after Manoj's feature patch

I did just that, and from my POV there's not much to it in the log.
Comment 18 Manoj N Palat CLA 2014-07-01 05:01:26 EDT
(In reply to Georgian Grec from comment #17)
> I did just that, and from my POV there's not much to it in the log.

Will give another patch to test asap
Comment 19 Manoj N Palat CLA 2014-07-01 10:05:57 EDT
Created attachment 244708 [details]
Luna Feature Patch

Please find the modified feature patch for Luna. This should log messages with PTB prefix. I've used the latest standard release, that is eclipse-standard-luna-R-win32-x86_64(You would have to download this version and try it out). Let me know if you have issues for using this version.
Comment 20 Georgian Grec CLA 2014-07-01 11:03:29 EDT
Created attachment 244709 [details]
Log after Manoj's second feature patch

Tried your second feature patch against Philippe's project, comment #11

Although the project builds fine (unlike my heavy workspace, which just throws the stackoverflow when building), the problem is still reproducible when searching for references of the Constants.java
Comment 21 Manoj N Palat CLA 2014-07-02 08:09:35 EDT
(In reply to Georgian Grec from comment #20)
> Created attachment 244709 [details]
> Log after Manoj's second feature patch
> 
> Tried your second feature patch against Philippe's project, comment #11
> 
> Although the project builds fine (unlike my heavy workspace, which just
> throws the stackoverflow when building), the problem is still reproducible
> when searching for references of the Constants.java

Thanks for the log Georgian. This feature patch did not have any additional fixes but had additional log messages to collect more info. And the good news is that I can reproduce this issue locally now and currently investigating.
Comment 22 Manoj N Palat CLA 2014-07-07 12:18:55 EDT
Created attachment 244857 [details]
Proposed Patch - WIP

this patch contains a small reproducible test case [with the proposed solution as per comment 5]

Stephan : Could you please take a look? I was also wondering whether an additional parameters.length > 0 check would help in mentionsAny() as an optimization for the most frequent case [if zero parameters is the most frequent]. Have added the check for WB as well in addition to PTB. Thanks.
Comment 23 Stephan Herrmann CLA 2014-07-07 16:44:04 EDT
preliminary comments:

(In reply to Manoj Palat from comment #22)
> this patch contains a small reproducible test case

congrats!

> I was also wondering whether an additional parameters.length > 0 check would
> help in mentionsAny() as an optimization for the most frequent case [if zero
> parameters is the most frequent].

I doubt that that is the most frequent case. Do you have any indications in that direction?


> Have added the check for WB as well in addition to PTB. Thanks.

Adding the check to WB didn't suffice?
Comment 24 Manoj N Palat CLA 2014-07-07 22:58:16 EDT
(In reply to Stephan Herrmann from comment #23)
> preliminary comments:
Thanks Stephan for the comments.

> > I was also wondering whether an additional parameters.length > 0 check would
> > help in mentionsAny() as an optimization for the most frequent case [if zero
> > parameters is the most frequent].
> 
> I doubt that that is the most frequent case. Do you have any indications in
> that direction?

I donot have enough data to say that this is the frequent case, though in this particular bug, there is no parameter - will not add this case - may put a comment.
 
> 
> > Have added the check for WB as well in addition to PTB. Thanks.
> 
> Adding the check to WB didn't suffice?

It did not suffice to put the check in WB since the loop were through RTB-PTB .
Will resubmit the patch after testing today.
Comment 25 Manoj N Palat CLA 2014-07-08 04:27:37 EDT
Created attachment 244874 [details]
Proposed Patch

Same as the above except for some minor comments
Comment 26 Stephan Herrmann CLA 2014-07-12 05:44:08 EDT
Manoj, I'd prefer to avoid the "inRecursiveFunction" story in PTB, because normally a PTB can be recursive only via TVB or WB, right?

What I see using your test case is, however, a recursion via a RawTypeBinding. We have this funny story that RTBs *may* have their "arguments" set, which is somewhat unexpected and confusing.

Could you please investigate the alternative approach where RTB#mentionsAny ignores its #arguments, perhaps by copying the implementation from TypeBinding?

The change in WildcardBinding, however, is good. Here we already have "inRecursiveFunction" and should indeed check this inside mentionsAny() - even though a change in RTB might suffice to fix this bug.
Comment 27 Manoj N Palat CLA 2014-07-14 00:24:48 EDT
(In reply to Stephan Herrmann from comment #26)

> We have this funny story that RTBs *may* have their
> "arguments" set, which is somewhat unexpected and confusing.
> 
> Could you please investigate the alternative approach where RTB#mentionsAny
> ignores its #arguments, perhaps by copying the implementation from
> TypeBinding?
> 


Thanks for the comments, Stephan. And yes, as you mentioned, we can implement RTB#mentionsAny(). However, I would think that we can return false directly in RTB#mentionsAny() instead of copying the implmenentation from TypeBinding. What scenario am I missing here?
Comment 28 Stephan Herrmann CLA 2014-07-14 05:08:12 EDT
(In reply to Manoj Palat from comment #27)
> (In reply to Stephan Herrmann from comment #26)
> 
> > We have this funny story that RTBs *may* have their
> > "arguments" set, which is somewhat unexpected and confusing.
> > 
> > Could you please investigate the alternative approach where RTB#mentionsAny
> > ignores its #arguments, perhaps by copying the implementation from
> > TypeBinding?
> > 
> 
> 
> Thanks for the comments, Stephan. And yes, as you mentioned, we can
> implement RTB#mentionsAny(). However, I would think that we can return false
> directly in RTB#mentionsAny() instead of copying the implmenentation from
> TypeBinding. What scenario am I missing here?

None, I guess :)

I was thinking of mechanically undoing the override in PTB, but you're right, an RTB can never be equal to a type parameter, so, yes, returning false could suffice.
Comment 29 Manoj N Palat CLA 2014-07-14 22:48:13 EDT
(In reply to Stephan Herrmann from comment #28)

Thanks Stephan. Code committed via http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=22f68238a49995ff90d0a5b80069c5ce0a399d4d

Georgian: Please use the latest build tomorrow to verify that the issue is resolved at your end.
Comment 30 Manoj N Palat CLA 2014-07-16 05:07:35 EDT
fixed
Comment 31 Georgian Grec CLA 2014-07-16 07:49:03 EDT
Great to hear that it's working! :-)

However, I cannot fully configure my workspace with 4.5 (N20140715-2000-win32-x86_64). Specifically, GlassFish tools won't install on Mars. They don't have a release for this version, yet.

Could you please provide a feature patch with this particular fix? I want to apply it on Luna. Either mail it to me, or attach it here, when you have the time.

Thank you!
Comment 32 Richard Steiger CLA 2014-07-23 00:02:39 EDT
(In reply to Georgian Grec from comment #31)
(In reply to Manoj Palat from comment #30)

Gregorian and Manoj, 

Great work tracking and fixing this. Can either of you provide any ETA on getting at least a beta patch up on the download pages? Our Java8 migration project has been blocked by this bug for several weeks, and we're eager to try-out the fix, hopefully it allows us to get the migration moving again. Promise to report back what we find :-).
Comment 33 Manoj N Palat CLA 2014-07-23 00:12:11 EDT
(In reply to Richard Steiger from comment #32)
> (In reply to Georgian Grec from comment #31)
> (In reply to Manoj Palat from comment #30)
> 
> Gregorian and Manoj, 
> 
> Great work tracking and fixing this. Can either of you provide any ETA on
> getting at least a beta patch up on the download pages? Our Java8 migration
> project has been blocked by this bug for several weeks, and we're eager to
> try-out the fix, hopefully it allows us to get the migration moving again.
> Promise to report back what we find :-).

Richard: You can take any of the latest downloads (nightly) of eclipse - this fix would be included in that.
Comment 34 Georgian Grec CLA 2014-07-23 08:14:19 EDT
(In reply to Manoj Palat from comment #33)
> (In reply to Richard Steiger from comment #32)
> > (In reply to Georgian Grec from comment #31)
> > (In reply to Manoj Palat from comment #30)
> > 
> > Gregorian and Manoj, 
> > 
> > Great work tracking and fixing this. Can either of you provide any ETA on
> > getting at least a beta patch up on the download pages? Our Java8 migration
> > project has been blocked by this bug for several weeks, and we're eager to
> > try-out the fix, hopefully it allows us to get the migration moving again.
> > Promise to report back what we find :-).
> 
> Richard: You can take any of the latest downloads (nightly) of eclipse -
> this fix would be included in that.

Hello Manoj.

As I mentioned in a comment above, I would like this fix on 4.4, and not 4.5 integration builds. Since we're using the Luna for production code, we cannot afford an unstable Mars.

I also tried the 4.4.1 M20140716-0800 (16 July 2014), but the fix isn't included there (should it?).

We would appreciate if you provided Richard and I with a feature patch for 4.4


Thank you.
Comment 35 Richard Steiger CLA 2014-07-23 19:47:53 EDT
Manoj, thanks for pointing me to nightly builds. I've been using the latest Mars build for the last day, it appears stable, and we've restarted our j8 migration project.

Thanks again,

-rjs
Comment 36 Manoj N Palat CLA 2014-07-23 23:17:20 EDT
(In reply to Richard Steiger from comment #35)
> Manoj, thanks for pointing me to nightly builds. I've been using the latest
> Mars build for the last day, it appears stable, and we've restarted our j8
> migration project.
> 
> Thanks again,
> 
> -rjs

Thanks Richard. Great to know that you have checked out the latest Mars. 

Just to make sure we are on the same page.

Do you still require this to be backported to 4.4 Luna (4.4.1 to be precise)? If yes, please let us know here. [Backporting is generally done only for regressions, and critical bugs - so if it is critical for you, we would backport it to 4.4].
Comment 37 Georgian Grec CLA 2014-07-24 04:18:46 EDT
Yes. The backport would be very helpful. 

I don't know about Richard, but for our system it is a blocker.
Comment 38 Srikanth Sankaran CLA 2014-07-24 08:27:13 EDT
Reopen to backport to 4.4.1

Jay, OK with back port ?
Comment 39 Jay Arthanareeswaran CLA 2014-07-24 10:13:24 EDT
(In reply to Srikanth Sankaran from comment #38)
> Reopen to backport to 4.4.1
> 
> Jay, OK with back port ?

Yep, Manoj please post a patch for R4_4_maintenance. Or let me know if the fix can straight away be be cherry-picked.
Comment 40 Manoj N Palat CLA 2014-07-27 23:34:23 EDT
(In reply to Jayaprakash Arthanareeswaran from comment #39)
> (In reply to Srikanth Sankaran from comment #38)
> > Reopen to backport to 4.4.1
> > 
> > Jay, OK with back port ?
> 
> Yep, Manoj please post a patch for R4_4_maintenance. Or let me know if the
> fix can straight away be be cherry-picked.

Thanks Jay for the green signal. Cherry Picked to R_4_4_maintenance via commit: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=R4_4_maintenance&id=56489f4301fc91391760f79a71fdfb45376254cc


Georgian: you can download the latest luna maintenance (R_4_4_maintenance) bits.
Comment 41 Manoj N Palat CLA 2014-07-28 02:26:23 EDT
cherry-picked for 4.4.1 as well. 
[Note: Original commit went for 4.5 M1]
Comment 42 Sasikanth Bharadwaj CLA 2014-08-06 01:51:19 EDT
Verified for 4.5 M1 using I20140804-2000 build
Comment 43 shankha banerjee CLA 2014-08-28 03:04:38 EDT
Verified for Eclipse Luna SR1 4.4.1 using M20140827-0800 build.
Comment 44 Richard Steiger CLA 2017-03-01 00:20:33 EST
This bug has resurfaced in neon-1, neon-2, and oxygen-m5. It is a complete and total showstopper for us, started happening 2 days ago. It's triggered by a workspace rebuild, including spontaneous ones (not in response to editing).

Currently running on jre1.8.0_121. I'll try other jre versions.

Strange to see this bad boy resurface after almost 3 years.

Thanks for any attention this gets.

-rjs
Comment 45 Stephan Herrmann CLA 2017-03-01 12:34:01 EST
(In reply to Richard Steiger from comment #44)
> This bug has resurfaced in neon-1, neon-2, and oxygen-m5. It is a complete
> and total showstopper for us, started happening 2 days ago. It's triggered
> by a workspace rebuild, including spontaneous ones (not in response to
> editing).
> 
> Currently running on jre1.8.0_121. I'll try other jre versions.
> 
> Strange to see this bad boy resurface after almost 3 years.
> 
> Thanks for any attention this gets.
> 
> -rjs

Let's for a minute please consider that you may be observing a new bug, so we'd need to collect the typical information: stacktrace, ideally reproducing source code etc. Plus: the exact version of plug-in org.eclipse.jdt.core. TIA.

Based on that information we can decide (a) reopen (b) file a new bug (c) do nothing.