xiaodududu / google-guice

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

singletions recreated many times on error, memebrs injected values may be null #676

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
1) Singletons should be not recreated many times if there was error whil 
constructing it. i.e.:
class T1, class T2 depends on T1 and class T3 depends on T1.
All of them singletons. Guice will try to create T1 three times: when creating 
itself, when creating T2 and T3.

2) Injected member may be null in case of dependent bean creation error. i.e.:
T1 class, T2 class have member of T1.
T1 failed to create due to exception, but T2 will not fail, rather it will have 
T1 fieled equal to null.

Attached patch to fix issues.

Original issue reported on code.google.com by kvas...@gmail.com on 25 Dec 2011 at 10:39

Attachments:

GoogleCodeExporter commented 9 years ago
Hi - a testcase for each of the scenarios would be really helpful to 
demonstrate the problem and validate the fix.

Original comment by mccu...@gmail.com on 14 Mar 2012 at 10:51

GoogleCodeExporter commented 9 years ago
class Test1
{
   Test1()
   {
       throw new RuntimeException();
   }
}

class Test2
{
   @Inject
   private Test1 member;
}

class Test3
{
   @Inject
   private Test1 member;
}

Just bind all classes as eager singletons.

1) Guice will fail to create Test1 class, but it will create Test2 normally. It 
should fail creating Test2 cause 'member' is not nullable.

2) Guice will try to create Test1 class twice. First when creating Test2 class 
and second one when creating Test3 class. It's really annoying that guice will 
try to create failing singleton 1000 times...

Original comment by kvas...@gmail.com on 24 Mar 2012 at 10:57

GoogleCodeExporter commented 9 years ago
Please provide a patch in JUnit form, with an assertion on the right behavior, 
so that it currently fails.

Original comment by sberlin on 5 Dec 2013 at 11:52

GoogleCodeExporter commented 9 years ago
Here is the testcase using JUnit. It currently fails but with patch applied it 
does not.

I wish this fix can make it into 4.0 release - few days ago I had a 10+ MB of 
output in log file from an exception thrown by Guice with 900+ messages in it 
and that is completely undebuggable.

p.s. there is a minor exception handling problem with the patch but it is 
probably easy to handle it properly.

Original comment by mikhail....@gmail.com on 12 Apr 2014 at 4:01

Attachments:

GoogleCodeExporter commented 9 years ago
Can someone from committers take a look at this issue please? It should be 
straightforward to address it.

Original comment by mikhail....@gmail.com on 5 May 2014 at 3:43