fmgasparino / google-gin

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

Private modules don't play nicely with eager singletons #149

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
With these declarations:

@GinModules({TestGinModule.class})
public interface Injector extends Ginjector {
}

public class TestGinModule extends PrivateGinModule {

  @Override
  protected void configure() {
    bind(Implementation.class).asEagerSingleton();
  }
}

public class Implementation {
  @Inject Implementation() {}
}

I get this error (with svn r197):

     [java] Compiling module com.google.dburrows.GinTestInput
     [java]    [ERROR] Errors in 'file:/home/dburrows/src/gin-test-cases/src/com/google/dburrows/client/GinTestInput.java'
     [java]       [ERROR]  Internal compiler error
     [java] java.lang.NoSuchMethodError: com.google.gwt.user.rebind.SourceWriter.print(Ljava/lang/String;[Ljava/lang/Object;)V
     [java]     at com.google.gwt.inject.rebind.GinjectorOutputter.outputBindings(GinjectorOutputter.java:167)
     [java]     at com.google.gwt.inject.rebind.GinjectorOutputter.output(GinjectorOutputter.java:143)
     [java]     at com.google.gwt.inject.rebind.GinjectorGeneratorImpl.generate(GinjectorGeneratorImpl.java:73)
     [java]     at com.google.gwt.inject.rebind.GinjectorGenerator.generate(GinjectorGenerator.java:75)
     [java]     at com.google.gwt.dev.javac.StandardGeneratorContext.runGenerator(StandardGeneratorContext.java:428)
     [java]     at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:38)
     [java]     at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.tryRebind(StandardRebindOracle.java:108)
     [java]     at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:54)
     [java]     at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:154)
     [java]     at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:143)
     [java]     at com.google.gwt.dev.Precompile$DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(Precompile.java:337)
     [java]     at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.doFindAdditionalTypesUsingRebinds(WebModeCompilerFrontEnd.java:95)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.process(AbstractCompiler.java:200)
     [java]     at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:444)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:123)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:234)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.access$200(AbstractCompiler.java:109)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler.compile(AbstractCompiler.java:522)
     [java]     at com.google.gwt.dev.jdt.BasicWebModeCompiler.getCompilationUnitDeclarations(BasicWebModeCompiler.java:112)
     [java]     at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.getCompilationUnitDeclarations(WebModeCompilerFrontEnd.java:47)
     [java]     at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:463)
     [java]     at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:32)
     [java]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:515)
     [java]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:433)
     [java]     at com.google.gwt.dev.Compiler.run(Compiler.java:203)
     [java]     at com.google.gwt.dev.Compiler.run(Compiler.java:173)
     [java]     at com.google.gwt.dev.Compiler$1.run(Compiler.java:145)
     [java]     at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:87)
     [java]     at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:81)
     [java]     at com.google.gwt.dev.Compiler.main(Compiler.java:152)
     [java] 
     [java] [ERROR] Unexpected
     [java] java.lang.NoSuchMethodError: com.google.gwt.user.rebind.SourceWriter.print(Ljava/lang/String;[Ljava/lang/Object;)V
     [java]     at com.google.gwt.inject.rebind.GinjectorOutputter.outputBindings(GinjectorOutputter.java:167)
     [java]     at com.google.gwt.inject.rebind.GinjectorOutputter.output(GinjectorOutputter.java:143)
     [java]     at com.google.gwt.inject.rebind.GinjectorGeneratorImpl.generate(GinjectorGeneratorImpl.java:73)
     [java]     at com.google.gwt.inject.rebind.GinjectorGenerator.generate(GinjectorGenerator.java:75)
     [java]     at com.google.gwt.dev.javac.StandardGeneratorContext.runGenerator(StandardGeneratorContext.java:428)
     [java]     at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:38)
     [java]     at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.tryRebind(StandardRebindOracle.java:108)
     [java]     at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:54)
     [java]     at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:154)
     [java]     at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:143)
     [java]     at com.google.gwt.dev.Precompile$DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(Precompile.java:337)
     [java]     at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.doFindAdditionalTypesUsingRebinds(WebModeCompilerFrontEnd.java:95)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.process(AbstractCompiler.java:200)
     [java]     at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:444)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:123)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:234)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.access$200(AbstractCompiler.java:109)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler.compile(AbstractCompiler.java:522)
     [java]     at com.google.gwt.dev.jdt.BasicWebModeCompiler.getCompilationUnitDeclarations(BasicWebModeCompiler.java:112)
     [java]     at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.getCompilationUnitDeclarations(WebModeCompilerFrontEnd.java:47)
     [java]     at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:463)
     [java]     at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:32)
     [java]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:515)
     [java]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:433)
     [java]     at com.google.gwt.dev.Compiler.run(Compiler.java:203)
     [java]     at com.google.gwt.dev.Compiler.run(Compiler.java:173)
     [java]     at com.google.gwt.dev.Compiler$1.run(Compiler.java:145)
     [java]     at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:87)
     [java]     at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:81)
     [java]     at com.google.gwt.dev.Compiler.main(Compiler.java:152)

In a real project, I've also seen it generate Ginjector code that fails because 
there's no get_Key* method, but I haven't reproduced that with a toy example 
yet.

Original issue reported on code.google.com by dburr...@google.com on 22 Apr 2011 at 9:06

GoogleCodeExporter commented 9 years ago
The stack trace here looks quite strange. It looks like a method cannot be 
called because it doesn't exist, but from the source I'd say it's there: 
http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/goo
gle/gwt/user/rebind/SourceWriter.java#53

It is possible that the custom class loader in Gin is causing this problem 
(although unlikely) and I'll look into that possibility. But I cannot see 
(right now) how this has anything with eager singletons in particular.

Original comment by aragos on 22 Apr 2011 at 10:32

GoogleCodeExporter commented 9 years ago
  So, this exception was because I had mismatched GWT and Gin versions.  Sorry.

  I am seeing some sort of issue with real code, but this must not be it.

Original comment by dburr...@google.com on 23 Apr 2011 at 12:19

GoogleCodeExporter commented 9 years ago
So, this exception was because I had mismatched GWT and Gin versions.
 Sorry.

  I am seeing some sort of issue with real code, but apparently it's harder
to isolate than I thought.  I'll close this issue and reopen it if I can
reproduce it for real.

Original comment by dburr...@google.com on 23 Apr 2011 at 12:20

GoogleCodeExporter commented 9 years ago
Ok, here's a working reproduction:

@GinModules({TestGinModule.class})
public interface Injector extends Ginjector {
}

public class TestGinModule extends PrivateGinModule {

  @Override
  protected void configure() {
    bind(Implementation.class).asEagerSingleton();
    bind(SubInterface.class).to(SubImplementation.class);
  }
}

public class Implementation {
  @Inject Implementation(SubInterface subInterface) {}
}

public Interface SubInterface {
}

public class SubImplementation implements SubInterface {
}

Please note that this is a minimal example.  In particular, Implementation must 
inject something -- if it has no dependencies, I don't see this bug.

The error I get is:

     [java]             [ERROR] Errors in '/home/dburrows/src/gin-test-cases/gen/com/google/dburrows/client/com_google_dburrows_client_GinTestInjectorImpl.java'
     [java]                [ERROR] Line 140: The method get_Key$type$com$google$dburrows$client$Implementation1$_annotation$$none$$() is undefined for the type com_google_dburrows_client_GinTestInjectorImpl

Inspection of the generated Ginjector reveals that the named method is present 
in an inner class (corresponding to the private module).  The obvious fix is to 
output a constructor for the private Ginjector that includes its eager 
singletons, and move them out of the root Ginjector.

Original comment by dburr...@google.com on 23 Apr 2011 at 12:47

GoogleCodeExporter commented 9 years ago
I created a fix for this problem, please review at 
http://codereview.appspot.com/4431063

Original comment by aragos on 25 Apr 2011 at 12:42

GoogleCodeExporter commented 9 years ago
Fixed in r198.

Original comment by aragos on 25 Apr 2011 at 8:09

GoogleCodeExporter commented 9 years ago
Thanks!  r198 fixes both my toy case and the real code where I ran into this 
bug.

Original comment by dburr...@google.com on 26 Apr 2011 at 8:28