fmgasparino / google-gin

Automatically exported from code.google.com/p/google-gin
Apache License 2.0
0 stars 0 forks source link

Stack overflow on circular dependency #43

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create two classes A and B
2. Bind them in Module as singletones
3. Create an injector with getA() method
4. Use constructor injection on both
5. Invoke the getA() method

What is the expected output? What do you see instead?
I expect that two linked instances of the classes are created. 
But I see stack overflow exception. See attached log file.

What version of the product are you using? On what operating system?
I use latest trunk r108, Windows vista, 
java version "1.6.0_10-beta"
Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b24)
Java HotSpot(TM) Client VM (build 11.0-b12, mixed mode, sharing)

Please provide any additional information below.

Please find test project attached.

Original issue reported on code.google.com by aectann on 8 Jun 2009 at 6:03

Attachments:

GoogleCodeExporter commented 9 years ago
I understand that the best way to get around the circular dependency is to 
inject a 
provider to delay the creation of one of objects in the circular dependency. 

I also noticed that circular dependency support is planned to be implemented 
(http://code.google.com/p/google-gin/source/browse/wiki/GuiceCompatibility.wiki)
. Is 
there an ETA for this?

Thanks.

Original comment by chris.k...@gmail.com on 13 Jun 2009 at 8:04

GoogleCodeExporter commented 9 years ago
Actually, from talking to Jesse Wilson the other day, it sounds like Guice's 
support
for circular dependencies without using providers is an undocumented hack and 
might
even go away (as a default anyway) someday.

One thing that is weird about Guice's magical circular dep breaking is that by 
using
a proxy, you lose object identity in a way you might not realize.

Some details: http://code.google.com/p/google-guice/issues/detail?id=220

So I am inclined to not implement support for circular dependencies, though we 
should
clearly detect this at compile time instead of blowing up at runtime.

Original comment by bstoler+code@google.com on 14 Jun 2009 at 11:58

GoogleCodeExporter commented 9 years ago
Thanks for the reply & feedback. I think what you are saying makes sense about 
losing 
object identity. Using providers is definitely provides a more clairvoyant view 
of 
object relations.

Original comment by chris.k...@gmail.com on 15 Jun 2009 at 10:41

GoogleCodeExporter commented 9 years ago
Is there any work being done on detection of circular dependency?

I ask because i'm having this problem from time to time, that by mistake i 
create circular dependency. It would definitely help if gin would tell me that 
im a moron instead of running for few minutes and then dying on 
StackOverflowError.

Original comment by amster1...@gmail.com on 12 Jun 2010 at 7:40

GoogleCodeExporter commented 9 years ago
As far as I can tell, no one is working on this problem at this time.

Original comment by aragos on 5 Jul 2010 at 12:51

GoogleCodeExporter commented 9 years ago
I just hit this as well, and I think you got a point, Provider is safer.

Original comment by dusan.ma...@gmail.com on 13 Dec 2010 at 3:18