mrszj / google-guice

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

Random NullPointerException when calling Guice.createInjector(..) #473

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Happens once in a while (1 out 3 to 4 times)

Exception in thread "main" java.lang.NullPointerException
    at com.google.inject.Initializer$InjectableReference.get(Initializer.java:145)
    at com.google.inject.ConstantFactory.get(ConstantFactory.java:39)
    at com.google.inject.SingleParameterInjector.inject(SingleParameterInjector.java:42)
    at com.google.inject.SingleParameterInjector.getAll(SingleParameterInjector.java:66)
    at com.google.inject.SingleMethodInjector.inject(SingleMethodInjector.java:84)
    at com.google.inject.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:99)
    at com.google.inject.MembersInjectorImpl$1.call(MembersInjectorImpl.java:76)
    at com.google.inject.MembersInjectorImpl$1.call(MembersInjectorImpl.java:74)
    at com.google.inject.InjectorImpl.callInContext(InjectorImpl.java:804)
    at com.google.inject.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:74)
    at com.google.inject.Initializer$InjectableReference.get(Initializer.java:145)
    at com.google.inject.Initializer.injectAll(Initializer.java:92)
    at com.google.inject.InjectorBuilder.injectDynamically(InjectorBuilder.java:171)
    at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:113)
    at com.google.inject.Guice.createInjector(Guice.java:92)
    at com.google.inject.Guice.createInjector(Guice.java:80)
        ...

Original issue reported on code.google.com by w.schoen...@gmail.com on 15 Apr 2010 at 4:10

GoogleCodeExporter commented 9 years ago
Using the version from the trunk shows a more detailed error while binding a 
custom 
scope. Changing the module order fixes the problem with the trunk. The problem 
still 
exists in 2.0.

Original comment by w.schoen...@gmail.com on 16 Apr 2010 at 1:54

GoogleCodeExporter commented 9 years ago
Can you paste the error from 2.0?

Original comment by limpbizkit on 16 Apr 2010 at 4:46

GoogleCodeExporter commented 9 years ago
The stacktrace is from 2.0 (latest official release from maven repo). This is 
the stack trace from the trunk version:

1) Error in custom provider, java.lang.NullPointerException
  at de.cosmocode.palava.ipc.ConnectionAwareUnitOfWorkScopeModule.configure(ConnectionAwareUnitOfWorkScopeModule.java:41)
  while locating de.cosmocode.palava.scope.UnitOfWorkScope
    for parameter 0 at de.cosmocode.palava.scope.UnitOfWorkScopeAspect.setUnitOfWorkScope(UnitOfWorkScopeAspect.aj:40)
  at de.cosmocode.palava.core.aop.AbstractPalavaAspect$1.configure(AbstractPalavaAspect.aj:46)

1 error
    at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:379)
    at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:183)
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:117)
    at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:90)
    at com.google.inject.Guice.createInjector(Guice.java:105)
    at com.google.inject.Guice.createInjector(Guice.java:90)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody0(DefaultFramework.java:97)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody1$advice(DefaultFramework.java:74)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody2(DefaultFramework.java:1)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody3$advice(DefaultFramework.java:74)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody4(DefaultFramework.java:1)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody5$advice(DefaultFramework.java:74)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody6(DefaultFramework.java:1)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody7$advice(DefaultFramework.java:74)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody8(DefaultFramework.java:1)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody9$advice(DefaultFramework.java:74)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody10(DefaultFramework.java:1)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody11$advice(DefaultFramework.java:74)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody12(DefaultFramework.java:1)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody13$advice(DefaultFramework.java:74)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody14(DefaultFramework.java:1)
    at de.cosmocode.palava.core.DefaultFramework.createInjector_aroundBody15$advice(DefaultFramework.java:74)
    at de.cosmocode.palava.core.DefaultFramework.<init>(DefaultFramework.java:97)
    at de.cosmocode.palava.core.Palava.createFramework(Palava.java:49)
    at de.cosmocode.palava.core.Main.<init>(Main.java:99)
    at de.cosmocode.palava.core.Main.main(Main.java:181)
Caused by: java.lang.NullPointerException
    at com.google.inject.internal.Initializer$InjectableReference.get(Initializer.java:145)
    at com.google.inject.internal.ConstantFactory.get(ConstantFactory.java:34)
    at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:43)
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:878)
    at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
    at com.google.inject.Scopes$1$1.get(Scopes.java:64)
    at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40)
    at com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)
    at com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)
    at com.google.inject.internal.SingleMethodInjector.inject(SingleMethodInjector.java:80)
    at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:109)
    at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:74)
    at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:72)
    at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:871)
    at com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:72)
    at com.google.inject.internal.Initializer$InjectableReference.get(Initializer.java:145)
    at com.google.inject.internal.Initializer.injectAll(Initializer.java:90)
    at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:181)
    ... 24 more

Original comment by w.schoen...@gmail.com on 16 Apr 2010 at 7:09

GoogleCodeExporter commented 9 years ago
Are you doing anything with threads?  Do some of your object's constructors 
spawn
other threads that require injection?  Is it possible to narrow the problem 
down to a
smaller full example?

Original comment by sberlin on 17 Apr 2010 at 2:08

GoogleCodeExporter commented 9 years ago
No, i do not spawn threads that require injection. The problem is, i can't 
reproduce
the problem. I don't see a pattern when it occurs.

Original comment by w.schoen...@gmail.com on 17 Apr 2010 at 5:18

GoogleCodeExporter commented 9 years ago
Issue 471 has been merged into this issue.

Original comment by sberlin on 19 Apr 2010 at 3:39

GoogleCodeExporter commented 9 years ago
I nailed it down to a custom scope which requires injection:
final UnitOfWorkScope scope = ...;
binder.requestInjection(scope);
binder.bindScope(UnitOfWork.class, scope);
binder.bind(UnitOfWorkScope.class).toInstance(scope);

I removed the requestInjection(..) call with a constructor parameter which i 
satisfy
with binder.getProvider(..), now everything seems to work.

Original comment by w.schoen...@gmail.com on 28 Apr 2010 at 2:15

GoogleCodeExporter commented 9 years ago
Awesome!  Do you think you'd be able to write a test that consistently 
reproduces the
failing behavior?  If it's something we can support, that'll help to figure out 
a fix
and verify it works.

It does make some sense that injecting into a Scope would fail, because how 
would you
bootstrap it... but then again, if the Scope isn't scoped to itself, it should
theoretically be possible.

Original comment by sberlin on 28 Apr 2010 at 4:46

GoogleCodeExporter commented 9 years ago
(And, if nothing else, we can figure out a better error message to show, if it's
behavior we can't support.)

Original comment by sberlin on 28 Apr 2010 at 4:46

GoogleCodeExporter commented 9 years ago
The problem is: The scope is participating in the injection process of other 
objects 
through a custom injection listener which calls an initialize method on every 
object. 
This method may annotated with a custom annotation which itself is adviced by 
an 
aspect using the scope to enter and exit before and after the method 
respectively. 
After writing this, it sounds extremely scary... 

Original comment by w.schoen...@gmail.com on 28 Apr 2010 at 4:49

GoogleCodeExporter commented 9 years ago
Take a look at this implementation of a concurrent singleton scope. Concurrent
injections and a request injection on a custom scope. Seems to work for him.

http://pastie.org/716802

Original comment by w.schoen...@gmail.com on 1 May 2010 at 10:42

GoogleCodeExporter commented 9 years ago
Bug is still alive! Please, fix it!

Original comment by abracham...@gmail.com on 10 Dec 2011 at 6:55

GoogleCodeExporter commented 9 years ago
Hi Abracham - any chance you could provide a testcase so we could recreate the 
bug and verify potential fixes?

Original comment by mccu...@gmail.com on 11 Dec 2011 at 12:49