On 1 Sep 2012, at 15:46, TonyD wrote:

> Thanks for the suggestion Jan.
> 
> I now check if the logger is null in the matcher which gets me passed that 
> issue.
> 
> Also, I think I solved my second issue with the listener itself throwing NPEs 
> from the encounter. I don't think I was using it right before. Basically, the 
> fix was something like this:
> 
> When I register a new injection listener with the encounter, I get the 
> providers from the encounter as fields in the listener. (Before I was trying 
> to get the objects from the providers as fields which resulted in the NPEs.)
> Then in the afterInjection method, I use the providers to actually get() the 
> instances.
FYI, I wrote a brief overview of TypeListeners, MembersInjectors, and 
InjectionListeners a while ago at the end of this blog post:

   
http://www.sonatype.com/people/2010/01/from-plexus-to-guice-2-the-guiceplexus-bridge-and-custom-bean-injection/

which people might find useful.

> i.e. In my InjectionListener class:
> 
>             // Fetch the log object provider from guice
>             private final Provider<Logger> logProvider = 
> encounter.getProvider(Logger.class);
> 
>             @Override
>             public void afterInjection(I injectee)
>             {
>                 Logger log = logProvider.get();
> ...
> 
> Hope that helps anyone else that runs into this.
> 
> On Saturday, 1 September 2012 02:14:04 UTC-4, Jan Galinski wrote:
> You are using "requestInject()" which also triggers the listener. I dont know 
> any lifecycle variable that I could check, so in cases like yours, I manually 
> check if injection has already taken place.
> So use "if log != null" to avoid the NullPointer
> Alternatively, adopt your Matcher, so that it excludes Log, then the listener 
> wont get called. 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "google-guice" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/google-guice/-/4EX2OTdGsT8J.
> 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?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" 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?hl=en.

Reply via email to