mehdikwa / google-gin

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

NPE when using Arrays.isList inside of generic class #173

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

It may not be the minimal case but in my case I trimmed it down to the 
following:

1. Create class A which has @Inject on its ctor and gets arguments injected via 
GWT-gin.

2. Create enum State inside of A.

3. Create class StateMachine<E extends Enum<E>> (see below) and include a 
member variable StateMachine<State> b; in class A (can leave uninitialized).

4. StateMachine should look like this:

public class StateMachine<E extends Enum<E>> {
    private class StateConfig {
        public final Collection<E> states;

        @SuppressWarnings("unchecked")
        public StateConfig(E... states) {
            this.states = new ArrayList<E>(Arrays.asList(states));
        }
    }
}

GWT compile fails with NPE from Gin:
     [java] java.lang.NullPointerException
     [java]     at com.google.gwt.inject.rebind.util.KeyUtil.javaToGwtMethod(KeyUtil.java:222)
     [java]     at com.google.gwt.inject.rebind.binding.ProviderMethodBinding.setProviderMethod(ProviderMethodBinding.java:60)
     [java]     at com.google.gwt.inject.rebind.BindingsProcessor$GuiceBindingVisitor.visit(BindingsProcessor.java:926)
     [java]     at com.google.gwt.inject.rebind.BindingsProcessor$GuiceBindingVisitor.visit(BindingsProcessor.java:898)
     [java]     at com.google.inject.internal.ProviderInstanceBindingImpl.acceptTargetVisitor(ProviderInstanceBindingImpl.java:62)
     [java]     at com.google.gwt.inject.rebind.BindingsProcessor$GuiceElementVisitor.visit(BindingsProcessor.java:827)
     [java]     at com.google.gwt.inject.rebind.BindingsProcessor$GuiceElementVisitor.visit(BindingsProcessor.java:820)
     [java]     at com.google.inject.internal.BindingImpl.acceptVisitor(BindingImpl.java:93)
     [java]     at com.google.gwt.inject.rebind.BindingsProcessor.createBindingsForModules(BindingsProcessor.java:409)
     [java]     at com.google.gwt.inject.rebind.BindingsProcessor.process(BindingsProcessor.java:238)
     [java]     at com.google.gwt.inject.rebind.GinjectorGeneratorImpl.generate(GinjectorGeneratorImpl.java:76)
     [java]     at com.google.gwt.inject.rebind.GinjectorGenerator.generate(GinjectorGenerator.java:47)
     [java]     at com.google.gwt.core.ext.GeneratorExtWrapper.generate(GeneratorExtWrapper.java:48)
     [java]     at com.google.gwt.core.ext.GeneratorExtWrapper.generateIncrementally(GeneratorExtWrapper.java:60)
     [java]     at com.google.gwt.dev.javac.StandardGeneratorContext.runGeneratorIncrementally(StandardGeneratorContext.java:647)
     [java]     at com.google.gwt.dev.cfg.RuleGenerateWith.realize(RuleGenerateWith.java:41)
     [java]     at com.google.gwt.dev.shell.StandardRebindOracle$Rebinder.rebind(StandardRebindOracle.java:78)
     [java]     at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:268)
     [java]     at com.google.gwt.dev.shell.StandardRebindOracle.rebind(StandardRebindOracle.java:257)
     [java]     at com.google.gwt.dev.DistillerRebindPermutationOracle.getAllPossibleRebindAnswers(DistillerRebindPermutationOracle.java:91)
     [java]     at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.doFindAdditionalTypesUsingRebinds(WebModeCompilerFrontEnd.java:96)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.process(AbstractCompiler.java:254)
     [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:173)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.compile(AbstractCompiler.java:288)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler$Sandbox$CompilerImpl.access$400(AbstractCompiler.java:139)
     [java]     at com.google.gwt.dev.jdt.AbstractCompiler.compile(AbstractCompiler.java:588)
     [java]     at com.google.gwt.dev.jdt.BasicWebModeCompiler.getCompilationUnitDeclarations(BasicWebModeCompiler.java:97)
     [java]     at com.google.gwt.dev.jdt.WebModeCompilerFrontEnd.getCompilationUnitDeclarations(WebModeCompilerFrontEnd.java:52)
     [java]     at com.google.gwt.dev.jjs.JavaToJavaScriptCompiler.precompile(JavaToJavaScriptCompiler.java:569)
     [java]     at com.google.gwt.dev.jjs.JavaScriptCompiler.precompile(JavaScriptCompiler.java:33)
     [java]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:284)
     [java]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:233)
     [java]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:145)
     [java]     at com.google.gwt.dev.Compiler.run(Compiler.java:232)
     [java]     at com.google.gwt.dev.Compiler.run(Compiler.java:198)
     [java]     at com.google.gwt.dev.Compiler$1.run(Compiler.java:170)
     [java]     at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)
     [java]     at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:82)
     [java]     at com.google.gwt.dev.Compiler.main(Compiler.java:177)

What version of the product are you using? On what operating system?
1.5, RHEL5 x64

Please provide any additional information below.

Tried to replace ... with [] - same error.

However if I replace Arrays.asList with manual loop, the error goes away:

this.states = new ArrayList<E>(states.length);
for(E state : states) {
  this.states.add(state);
}

Original issue reported on code.google.com by kamot...@gmail.com on 12 Mar 2012 at 7:55

GoogleCodeExporter commented 9 years ago
Darn, just realized that this is because of wrong import suggested 
automatically by Eclipse. Switching to java.util.Arrays fixes everything, 
please feel free to close this Issue. Or, consider it a request to add better 
messaging during NPE to save diagnostic time for issues like this (I wasted 3 
hours at least trying to localize this code).

Original comment by kamot...@gmail.com on 12 Mar 2012 at 8:03

GoogleCodeExporter commented 9 years ago
Thanks for the bug report (even though it turned out not to be such a big 
problem :). This code has already changed significantly in HEAD and I think 
there should be better error messages now if we can't resolve a type.

Original comment by aragos on 12 Mar 2012 at 8:09