fmgasparino / google-gin

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

GinModule's configure() gets called twice #36

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
(code/error message taken from shybyte's mailinglist post "GinTutorial
doesn't work for me"):
public interface Localization
{
    public String MSG_HELLO_WORLD();

}

public class LocalizationImpl implements Localization
{

    @Override
    public String MSG_HELLO_WORLD()
    {
        return "Hello World!";
    }

}

public class ClientGinModule extends AbstractGinModule
{
    @Override
    protected void configure()
    {
        bind(Localization.class).to(LocalizationImpl.class);
    }

}

@GinModules(ClientGinModule.class)
public interface LocalizationGinjector extends Ginjector
{
    Localization getLocalization();

} 

What is the expected output? What do you see instead?
Expected: don't knwo, never seen it ;)
What i got: 
In hosted mode I got:

[ERROR] Errors from Guice: Guice creation errors:

1) A binding to prototype.gin.client.Localization was already
configured at com.google.gwt.inject.rebind.LieToGuiceModule
$ImplicitBindingModule.configure(LieToGuiceModule.java:70).
  at prototype.gin.client.ClientGinModule.configure
(ClientGinModule.java:21)

1 error
com.google.inject.CreationException: Guice creation errors:

1) A binding to prototype.gin.client.Localization was already
configured at com.google.gwt.inject.rebind.LieToGuiceModule
$ImplicitBindingModule.configure(LieToGuiceModule.java:70).
  at prototype.gin.client.ClientGinModule.configure
(ClientGinModule.java:21)

1 error
        at
com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist
(Errors.java:342)
        at com.google.inject.InjectorBuilder.initializeStatically
(InjectorBuilder.java:152)
        at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:105)
        at com.google.inject.Guice.createInjector(Guice.java:92)
        at
com.google.gwt.inject.rebind.BindingsProcessor.validateModulesUsingGuice
(BindingsProcessor.java:309)
        at com.google.gwt.inject.rebind.BindingsProcessor.process
(BindingsProcessor.java:180)
        at com.google.gwt.inject.rebind.GinjectorGeneratorImpl.generate
(GinjectorGeneratorImpl.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
(StandardRebindOracle.java:113)
        at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind
(StandardRebindOracle.java:62)
        at com.google.gwt.dev.shell.StandardRebindOracle.rebind
(StandardRebindOracle.java:172)
        at com.google.gwt.dev.shell.ShellModuleSpaceHost.rebind
(ShellModuleSpaceHost.java:114)
        at com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:474)
        at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate
(ModuleSpace.java:365)
        at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:
39)
        at com.google.gwt.core.client.GWT.create(GWT.java:91)
        at prototype.gin.client.GinPrototype.<init>(GinPrototype.java:32)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
        at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate
(ModuleSpace.java:373)
        at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:318)
        at com.google.gwt.dev.shell.BrowserWidget.attachModuleSpace
(BrowserWidget.java:343)
        at com.google.gwt.dev.shell.moz.BrowserWidgetMoz.access$100
(BrowserWidgetMoz.java:35)
        at com.google.gwt.dev.shell.moz.BrowserWidgetMoz
$ExternalObjectImpl.gwtOnLoad(BrowserWidgetMoz.java:58)
        at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native
Method)
        at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:
1428)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2840)
        at com.google.gwt.dev.SwtHostedModeBase.processEvents
(SwtHostedModeBase.java:235)
        at com.google.gwt.dev.HostedModeBase.pumpEventLoop
(HostedModeBase.java:558)
        at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405)
        at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)

When compiling to javascript I got:

Compiling module prototype.gin.GinPrototype
   Refreshing module from source
      Refreshing TypeOracle
         Processing types in compilation unit: file:/home/marco/
workspace/GinPrototype/src/prototype/gin/client/
LocalizationGinjector.java
            Found type 'LocalizationGinjector'
               Resolving annotation '@GinModules
(ClientGinModule.class)'
                  [ERROR]
java.lang.ClassNotFoundException: prototype.gin.client.ClientGinModule
        at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:323)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:268)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:336)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:264)
        at com.google.gwt.dev.javac.TypeOracleMediator.getClassLiteral
(TypeOracleMediator.java:763)
        at
com.google.gwt.dev.javac.TypeOracleMediator.getAnnotationElementValue
(TypeOracleMediator.java:674)
        at
com.google.gwt.dev.javac.TypeOracleMediator.createAnnotationInstance
(TypeOracleMediator.java:442)
        at com.google.gwt.dev.javac.TypeOracleMediator.resolveAnnotation
(TypeOracleMediator.java:836)
        at com.google.gwt.dev.javac.TypeOracleMediator.resolveAnnotations
(TypeOracleMediator.java:857)
        at com.google.gwt.dev.javac.TypeOracleMediator.resolveTypeDeclaration
(TypeOracleMediator.java:1384)
        at com.google.gwt.dev.javac.TypeOracleMediator.addNewUnits
(TypeOracleMediator.java:389)
        at com.google.gwt.dev.javac.TypeOracleMediator.refresh
(TypeOracleMediator.java:417)
        at com.google.gwt.dev.javac.CompilationState.refresh
(CompilationState.java:179)
        at com.google.gwt.dev.javac.CompilationState.<init>
(CompilationState.java:93)
        at com.google.gwt.dev.cfg.ModuleDef.getCompilationState
(ModuleDef.java:264)
        at com.google.gwt.dev.Precompile.precompile(Precompile.java:283)
        at com.google.gwt.dev.Compiler.run(Compiler.java:170)
        at com.google.gwt.dev.Compiler$1.run(Compiler.java:124)
        at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:
84)
        at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger
(CompileTaskRunner.java:78)
        at com.google.gwt.dev.Compiler.main(Compiler.java:131)
[ERROR] Unexpected
java.lang.NullPointerException
        at
com.google.gwt.dev.javac.TypeOracleMediator.getAnnotationElementValue
(TypeOracleMediator.java:704)
        at
com.google.gwt.dev.javac.TypeOracleMediator.createAnnotationInstance
(TypeOracleMediator.java:442)
        at com.google.gwt.dev.javac.TypeOracleMediator.resolveAnnotation
(TypeOracleMediator.java:836)
        at com.google.gwt.dev.javac.TypeOracleMediator.resolveAnnotations
(TypeOracleMediator.java:857)
        at com.google.gwt.dev.javac.TypeOracleMediator.resolveTypeDeclaration
(TypeOracleMediator.java:1384)
        at com.google.gwt.dev.javac.TypeOracleMediator.addNewUnits
(TypeOracleMediator.java:389)
        at com.google.gwt.dev.javac.TypeOracleMediator.refresh
(TypeOracleMediator.java:417)
        at com.google.gwt.dev.javac.CompilationState.refresh
(CompilationState.java:179)
        at com.google.gwt.dev.javac.CompilationState.<init>
(CompilationState.java:93)
        at com.google.gwt.dev.cfg.ModuleDef.getCompilationState
(ModuleDef.java:264)
        at com.google.gwt.dev.Precompile.precompile(Precompile.java:283)
        at com.google.gwt.dev.Compiler.run(Compiler.java:170)
        at com.google.gwt.dev.Compiler$1.run(Compiler.java:124)
        at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:
84)
        at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger
(CompileTaskRunner.java:78)
        at com.google.gwt.dev.Compiler.main(Compiler.java:131) 

What version of the product are you using? On what operating system?
Guice Version: svn r937
Gin Version: svn r95
GWT Version: 1.6.4
Plaform: Linux 32 Bit (Ubuntu 9.04)

Please provide any additional information below.
I worked around that issue by adding a check to the implementation of
GinModule.
I'll take shybyte's code as an example:

public class ClientGinModule extends AbstractGinModule
{
    private static boolean configured = false;

    @Override
    protected void configure()
    {
        if(!configured) {
            bind(Localization.class).to(LocalizationImpl.class);
            configured = true;
        }
    }

} 

That fixed the duplicate binding errors, but on the other hand made GIN
completly ignore every binding i defined, meaning that  Localization would
not be bound to LocalizationImpl although configure() gets called for sure.

Original issue reported on code.google.com by marc.die...@gmail.com on 5 May 2009 at 9:27

GoogleCodeExporter commented 9 years ago
One remark: 
After using an own compile script (instead of the compile button of the Google 
Plugin
for Eclipse)
I got the "Guice creation errors" also when compiling to javascript and not 
only in
hosted mode.

Original comment by shyb...@gmail.com on 5 May 2009 at 9:57

GoogleCodeExporter commented 9 years ago
tried it again today with guice 2.0 and gin r108.
everything works a expected now.

Original comment by marc.die...@gmail.com on 3 Jun 2009 at 1:46

GoogleCodeExporter commented 9 years ago

Original comment by bstoler+code@google.com on 3 Jun 2009 at 3:35

GoogleCodeExporter commented 9 years ago
Hello,

I have exactly the same problem (double configuration) and I use guice 2.0. I 
also
use ubuntu 9.04, and tried compiling with GWT 1.64 and 1.7. I use eclipse and 
the
google plugin to compile. I try to bind an interface D to DImpl in my module 
exactly
as described above. The error I get is: 

1) A binding to com.mycomp.D was already configured at
com.google.gwt.inject.rebind.LieToGuiceModule$ImplicitBindingModule.configure(Li
eToGuiceModule.java:70).
  at com.mycomp.MyClientModule.configure(MyClientModule.java:14)

I really suspect a configration problem on my side as other people have 
succeeded
compiling with the same settings, but I fail to see what is wrong.

Original comment by savolain...@gmail.com on 9 Aug 2009 at 7:13

GoogleCodeExporter commented 9 years ago
Like the previous commenter, I'm on Linux and compiling my GWT modules results 
in the
same NullPointerException. Are you sure this issue has been fixed? GWT version 
1.7,
Java version 1.6.0_16.

The first message in the following thread describes the problem I'm having in a 
bit
more detail:

http://groups.google.com/group/google-web-toolkit/browse_thread/thread/38a173d8b
0d11359/f165bf1b88cab945?lnk=raot

Note that the author got things working because Eclipse was compiling the Gin 
module
into a class file, which happened to be on the classpath of the GWT compiler. 
But
surely you shouldn't need to compile client classes as normal Java before 
compiling
the GWT modules?

Original comment by p.ledbr...@gmail.com on 19 Aug 2009 at 3:33

GoogleCodeExporter commented 9 years ago
Ooops, forgot to mention Gin version: r109

Original comment by p.ledbr...@gmail.com on 19 Aug 2009 at 3:34

GoogleCodeExporter commented 9 years ago
And in NetBeans 6.7.1 in order to get GIN overcome that 
ClassNotFound/NullPointer
issue you also have to manually add "<project 
folder>/build/web/WEB-INF/classes" path
into project classpath (i.e. among other libraries).

Original comment by Bulatju@gmail.com on 5 Sep 2009 at 10:26

GoogleCodeExporter commented 9 years ago
I have the same problem too. I set a breakpoint on the firstline of configure()
method and it stops twice.

Original comment by wbabac...@googlemail.com on 26 May 2010 at 12:39

GoogleCodeExporter commented 9 years ago
I see this as well. The first call seems fine but the second call has this as 
part of the stack...

GinModuleAdapter.configure(Binder) line: 40 
Elements$RecordingBinder.install(Module) line: 223  
Elements.getElements(Stage, Iterable<Module>) line: 101 
InjectorShell$Builder.build(Initializer, BindingProcessor, Stopwatch, Errors) 
line: 135   
InjectorBuilder.build() line: 102   
Guice.createInjector(Stage, Iterable<Module>) line: 92  
BindingsProcessor.validateModulesUsingGuice(List<Module>) line: 378 
BindingsProcessor.process() line: 218   
GinjectorGeneratorImpl.generate() line: 76  
GinjectorGenerator.generate(TreeLogger, GeneratorContext, String) line: 47  

It looks like the nested Guice infra is creating a dummy injector for 
validation. Is this correct and, if so, then 
can we be sure that the dummy injector created by Guice is discarded i.e. two 
calls to configure() are actually 
ok?

Original comment by steve.buikhuizen@gmail.com on 2 Jun 2010 at 9:54

GoogleCodeExporter commented 9 years ago
Yes, this should be fine. We run the validation injector (which is never saved) 
and
then run the config again when we read the actual bindings.

Original comment by aragos on 2 Jun 2010 at 8:58