-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
From lorenzo@intelerad.com on April 08, 2014 14:35:22
I apologize if this issue is already known. I only found 2 issues mentioning the InjectionListener and none seemed related to the following. Description of the issue: It seems that instantiating singleton instances within the scope of InjectionListener.afterInjection() causes Guice to associate an instance to a type instead of associating it to a key (type and annotation).
The attached application InjectorListenerWithSingletons attempts to illustrate the issue:
* Bind an annotated interface to an implementation as a singleton.
- Bind the same interface with a different annotation to the same implementation as a singleton.
- Retrieve instances of both annotated interfaces and compare them (using ==)
- Repeat the same steps but this time instantiating the annotated interfaces within an InjectionListener.afterInjection() Steps to reproduce: 1. Execute InjectorListenerWithSingletons as is with java assertions enabled. It should fail with error "KEY_1 and KEY_2 should be different".
- Comment out line 63 (p1.get()) or line 64 (p2.get()), or both, and re-run the application. This time the test should pass.
Let me know if there is a fundamental flaw in the design of the test, or if you need more details or additional tests.
Thanks for your time.
Attachment: gist
InjectorListenerWithSingletons.java
Original issue: http://code.google.com/p/google-guice/issues/detail?id=802