Comment #2 on issue 627 by joshgr: Bug in com.google.inject.internal.Initializer
http://code.google.com/p/google-guice/issues/detail?id=627

I'm witnessing the same issue (intermittently) in a codebase that also combines Jackson JSON with Guice. I don't have an isolated reproduction to offer, but I can add some additional context that I hope may help track down the cause:

I've noticed that the error occurs inside of a call to Injector.getInstance() which is invoked *within* the constructor of a guice-managed eager singleton: I have a singleton whose constructor loads some JSON configuration; during the JSON deserialization, we call injector.getInstance(...) to populate a field on a deserialized configuration object (this is perhaps a bad idea, but I would at least hope for more clear exception if we're doing something wrong). This has worked for us in the past, but some recent change is frequently (but not always?!) resulting in a NPE (see below for the stacktrace).

One more note: the eagerSingleton constructor is actually being invoked A SECOND TIME when the exception is thrown; a breakpoint at the top of the constructor is hit twice prior to the exception. I can't explain this; I wasn't able to locate any circular dependencies in this area of the code.

Hope this helps!


1) Error in custom provider, java.lang.NullPointerException

1 error
        at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:987)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1009)
  [... context elided ...]
Caused by: java.lang.NullPointerException
at com.google.inject.internal.Initializer$InjectableReference.get(Initializer.java:147)
        at 
com.google.inject.internal.ConstantFactory.get(ConstantFactory.java:35)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46) at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1031) at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
        at com.google.inject.Scopes$1$1.get(Scopes.java:65)
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.ConstructorInjector.construct(ConstructorInjector.java:84) at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254) at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46) at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1031) at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
        at com.google.inject.Scopes$1$1.get(Scopes.java:65)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:40) at com.google.inject.internal.SingleFieldInjector.inject(SingleFieldInjector.java:53) at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:110) at com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:94) at com.google.inject.internal.ConstructorBindingImpl$Factory.get(ConstructorBindingImpl.java:254)
        at 
com.google.inject.internal.InjectorImpl$4$1.call(InjectorImpl.java:978)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1031)
        at com.google.inject.internal.InjectorImpl$4.get(InjectorImpl.java:974)

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to