vipx / google-guice

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

Unexpected interaction between InjectionListener and singleton bindings #802

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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".
2. 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.

Original issue reported on code.google.com by lore...@intelerad.com on 8 Apr 2014 at 6:35

Attachments: