Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with multibindings and binding annotations? #966

Closed
mumrah opened this issue Nov 24, 2015 · 3 comments
Closed

Problem with multibindings and binding annotations? #966

mumrah opened this issue Nov 24, 2015 · 3 comments

Comments

@mumrah
Copy link

mumrah commented Nov 24, 2015

I have two modules that bind a set of strings like:

In FooModule:

Multibinder<String> fooThingsBinder = Multibinder.newSetBinder(binder(), String.class, Foo.class);
...
for(String foo: fooThings) {
  fooThingsBinder.addBinding().toInstance(foo);
}

And something similar in BarModule. Then elsewhere in the code I get these sets injected like:

public class FooResource(@Foo Set<String> fooThings, ...) { ... }

and something similar in BarResource.

What I'm seeing is that one of these sets non-deterministically gets injected to both resource classes. E.g., the foo things end up in FooResource and BarResource, or vice-versa.

I have tried using the @Named binding annotation as well, with the same results. I have another multi-binding that uses different types instead binding annotations, and it is working fine.

I'll try to come up with a test case later today/this week as time allows. I've worked around this for now by creating separate sub-types for the foo/bar things.

@sameb
Copy link
Member

sameb commented Nov 24, 2015

It's very unlikely this is a bug, since this is pretty fundamental and many things would be broken if this were broken. Please come up with a test case where you can reproduce and I'll take a look.

@mumrah
Copy link
Author

mumrah commented Nov 25, 2015

@sameb that was my initial thought as well. I put together a test case anyways and cannot reproduce the problem. My application is using Jersey 2.x (which uses HK2) and the jersey2-guice module from Squarespace, so I'm guessing something is not getting properly translated in the guice -> hk2 bridge.

@mumrah
Copy link
Author

mumrah commented Nov 25, 2015

I opened an issue on the jersey2-guice project if anyone is interested: Squarespace/jersey2-guice#34

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants