frjaeger220 / google-guice

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

NPE in #getDependencies() of ProviderInstanceBinding for Multibinder in Stage.TOOL #297

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
private static class Multimodule extends AbstractModule {
  @Override
  protected void configure() {
    Multibinder<String> setBinder = Multibinder.newSetBinder(binder(), String.class);
    setBinder.addBinding().toInstance("One");
    setBinder.addBinding().toInstance("Two");
    setBinder.addBinding().toInstance("Three");
  }
}

Injector injector = Guice.createInjector(Stage.TOOL, new Multimodule());
ProviderInstanceBinding<?> binding =
    (ProviderInstanceBinding<?>) injector.getBinding(Key.get(new TypeLiteral<Set<String>>() {}));
// throws NullPointerException
binding.getDependencies();

It seems that in TOOL mode, the RealMultibinder#initialize() method is not 
called, so the 
Dependency Set is never created.

Primary expectation is for this to not cause an exception, but secondary 
expectation is for the 
Dependencies to be available even in TOOL mode.

Original issue reported on code.google.com by phopkins on 30 Dec 2008 at 8:18

GoogleCodeExporter commented 9 years ago
This sucks, but I dont' have an immediate fix. Multibinder figures out what its 
dependencies are when it's 
injected. So it can't really return anything from a call to getDependencies() 
that happens in TOOL stage...

Original comment by limpbizkit on 30 Dec 2008 at 10:01

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 30 Dec 2008 at 11:39

GoogleCodeExporter commented 9 years ago
Do you mind if I submit a patch for this? Throwing seems bad. Would you prefer 
an empty set or null from 
InstanceBinder#getDependencies()?

Original comment by phopkins on 30 Dec 2008 at 11:55

GoogleCodeExporter commented 9 years ago
I actually prefer throwing! Maybe an IllegalStateException? The problem is that 
the dependencies aren't known in 
tool mode...

Original comment by limpbizkit on 31 Dec 2008 at 5:26

GoogleCodeExporter commented 9 years ago
Throwing an unchecked exception is probably bad for a tool, since the use of a 
single Multibinder in TOOL mode 
would likely cause the SPI client to blow up unless we write the @throws 
JavaDoc in all caps.

How about null? It seems like a reasonably recoverable return value.

Original comment by phopkins on 6 Jan 2009 at 5:16

GoogleCodeExporter commented 9 years ago
whoops, accidentally removed Jesse when I reassigned this.

Original comment by phopkins on 7 Jan 2009 at 3:45

GoogleCodeExporter commented 9 years ago
Issue 309 has been merged into this issue.

Original comment by sberlin on 25 Apr 2010 at 9:40

GoogleCodeExporter commented 9 years ago
fixed in r1154

Original comment by sberlin on 26 Apr 2010 at 2:13