michaelwiles / google-gin

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

Problem in BindingProcessor when trying to bind inner class of inner class. #72

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Not entirely sure, but I think the way NameGenerator#binaryNameToSourceName 
works has a bug in that it only replaces the last "$". In my case, I had
a Gin module that was a static inner class of my entry point class, and a 
second class that was a static inner class of the Gin module. 

Something like:

public class A extends EntryPoint {
  [...]
  public static class SomeGinModule extends AbstractGinModule {
    protected void configure() {
      [...]
      bind(new TypeLiteral<SomeInterface>).toProvider(ModelProvider.class);
      [...]
    }

    private static class ModelProvider implements Provider<SomeClass> {
      [..]
    }
  }
}

I had this exception at generation phase:
java.lang.NullPointerException: null    at 
com.google.gwt.inject.rebind.BindingsProcessor.createImplicitBinding(Bindin
gsProcessor.java:425)   at 
com.google.gwt.inject.rebind.BindingsProcessor.createImplicitBindingForUnre
solved(BindingsProcessor.java:231)  at 
com.google.gwt.inject.rebind.BindingsProcessor.createImplicitBindingsForUnr
esolved(BindingsProcessor.java:219)     at 
com.google.gwt.inject.rebind.BindingsProcessor.process(BindingsProcessor.ja
va:211)     at 
com.google.gwt.inject.rebind.GinjectorGeneratorImpl.generate(GinjectorGener
atorImpl.java:76)   at 
com.google.gwt.inject.rebind.GinjectorGenerator.generate(GinjectorGenerator
.java:47)   at 
com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:49)   
at 
com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.tryRebind(StandardRe
bindOracle.java:108)    at 
com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebin
dOracle.java:54)    at 
com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.j
ava:154)    at 
com.google.gwt.dev.shell.ShellModuleSpaceHost.rebind(ShellModuleSpaceHost.j
ava:117)    at 
com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:538)   at 
com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:425)  
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:39)     
at com.google.gwt.core.client.GWT.create(GWT.java:98)   at 
com.google.ads.syn.adsense.fe.apps.allowandblockads.gwt.settings.testing.Fa
keAllowAndBlockAdsSettingsModule.getGwtCreatedInjector(FakeAllowAndBlockAds
SettingsModule.java:48)     at 
com.google.ads.syn.adsense.fe.apps.config.gin.ActivityEntryPoint.getActivit
yMapProvider(ActivityEntryPoint.java:41)    at 
com.google.ads.syn.adsense.fe.apps.config.gin.ActivityEntryPoint.access$0(A
ctivityEntryPoint.java:39)  at 
com.google.ads.syn.adsense.fe.apps.config.gin.ActivityEntryPoint$1.getActiv
ity(ActivityEntryPoint.java:52)     at 
com.google.ads.syn.publisher.client.gwt.common.navigation.AbstractActivityC
reator$1.onSuccess(AbstractActivityCreator.java:37)     at 
com.google.gwt.core.client.GWT.runAsyncWithoutCodeSplitting(GWT.java:276)   
at com.google.gwt.core.client.GWT.runAsync(GWT.java:220)    at 
com.google.ads.syn.publisher.client.gwt.common.navigation.AbstractActivityC
reator.createActivity(AbstractActivityCreator.java:29)  at 
com.google.ads.syn.publisher.client.gwt.common.navigation.NavigationControl
ler.getActivityAndStart(NavigationController.java:245)  at 
com.google.ads.syn.publisher.client.gwt.common.navigation.NavigationControl
ler.access$6(NavigationController.java:236)     at 
com.google.ads.syn.publisher.client.gwt.common.navigation.NavigationControl
ler$2.onSuccess(NavigationController.java:226)  at 
com.google.ads.syn.publisher.client.gwt.common.navigation.NavigationControl
ler$2.onSuccess(NavigationController.java:1)    at 
com.google.ads.syn.publisher.client.gwt.common.navigation.StandardApplicati
onStarter.prepare(StandardApplicationStarter.java:59)   at 
com.google.ads.syn.publisher.client.gwt.common.navigation.NavigationControl
ler.initializeAndStartActivity(NavigationController.java:221)   at 
com.google.ads.syn.publisher.client.gwt.common.navigation.NavigationControl
ler.startActivity(NavigationController.java:211)    at 
com.google.ads.syn.publisher.client.gwt.common.navigation.NavigationControl
ler.startActivity(NavigationController.java:173)    at 
com.google.ads.syn.publisher.client.gwt.common.navigation.NavigationControl
ler.autoStartIfNeeded(NavigationController.java:143)    at 
com.google.ads.syn.publisher.client.gwt.common.navigation.NavigationControl
ler.install(NavigationController.java:137)  at 
com.google.ads.syn.publisher.client.gwt.common.ActivityInstaller.install(Ac
tivityInstaller.java:67)    at 
com.google.ads.syn.adsense.fe.apps.config.gin.ActivityEntryPoint.onModuleLo
ad(ActivityEntryPoint.java:49)  at 
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
9)  at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
l.java:25)  at java.lang.reflect.Method.invoke(Method.java:597)     at 
com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:380)   at 
com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler
.java:172)  at 
com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChan
nelServer.java:345)     at 
com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java
:192)   at java.lang.Thread.run(Thread.java:619)

so I debugged the generation process, and it turns out that in 
createImplicitBinding the "keyUtil.getRawClassType" call returns null 
because the object in the "allTypes" map in TypeOracle can be found with
the name resulting from the substitution of both "$" with dots (i.e. both 
the one for the inclusion of the gin module class in the entry point one 
and one for the inclusion of the bound class in the gin module, but the 
replace in KeyUtil only changes the second one.

Obvious workaround: move the class definition out of the inner class and at 
its same level (i.e.: as an inner class of the EntryPoint itself).

Original issue reported on code.google.com by baronce...@google.com on 11 Dec 2009 at 1:59

GoogleCodeExporter commented 9 years ago
Thanks for bringing this to my attention, I'll take a look into it. Solution is
probably to recursively check for enclosing classes.

Original comment by aragos on 11 Dec 2009 at 3:56

GoogleCodeExporter commented 9 years ago
Fix submitted for review: http://codereview.appspot.com/176069

Original comment by aragos on 13 Dec 2009 at 8:48

GoogleCodeExporter commented 9 years ago

Original comment by aragos on 16 Dec 2009 at 9:51