google-code-export / google-guice

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

Assisted injection of inherited specialized interfaces fails #332

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

let's say the following code :

package guice.test;

import com.google.inject.*;
import com.google.inject.assistedinject.*;

class Parent { @Inject Parent(@Assisted Object o) {} }
class Child extends Parent { @Inject Child(@Assisted Object o) { super(o); } }

interface ParentFactory { Parent create(Object o); }
interface ChildFactory extends ParentFactory { @Override Child
create(Object o); }

public class Test {
    public static void main(String[] args) {
        Guice.createInjector(new AbstractModule() {
            @Override protected void configure() {

bind(ChildFactory.class).toProvider(FactoryProvider.newFactory(ChildFactory.clas
s,
Child.class));
            }
        });
    }
}

Here is the stacktrace I found:

Exception in thread "main" java.lang.IllegalAccessError: tried to access
class com.google.inject.ConfigurationException from class
com.google.inject.assistedinject.FactoryProvider
    at
com.google.inject.assistedinject.FactoryProvider.newConfigurationException(Facto
ryProvider.java:241)
    at
com.google.inject.assistedinject.FactoryProvider.createMethodMapping(FactoryProv
ider.java:164)
    at
com.google.inject.assistedinject.FactoryProvider.<init>(FactoryProvider.java:105
)
    at
com.google.inject.assistedinject.FactoryProvider.newFactory(FactoryProvider.java
:99)
    at guice.test.Test$1.configure(Test.java:16)
    at com.google.inject.AbstractModule.configure(AbstractModule.java:66)
    at com.google.inject.BinderImpl.install(BinderImpl.java:199)
    at com.google.inject.Guice.createInjector(Guice.java:77)
    at com.google.inject.Guice.createInjector(Guice.java:53)
    at com.google.inject.Guice.createInjector(Guice.java:43)
    at guice.test.Test.main(Test.java:14)

It is failing for two reasons.
1. The newConfiguration fails for the reason mentionned in the stacktrace
above.
2. The newConfiguration is called because there are more "create" methods
than constructors. In absolute, that is right, because there is one
constructor and two create methods, but the two methods of the factory have
the exact same signature (but not the same return type), meaning that the
method of ChildFactory overrides the method of ParentFactory, and this
exception should not be raised in this case, because there is only one
actual constructor and only one actual "create" method.

Original issue reported on code.google.com by ogregoire on 13 Feb 2009 at 8:40

GoogleCodeExporter commented 9 years ago
I was not aware that there was a recent snapshot (2009/2/5). These bugs are 
fixed in
that new version!

Original comment by ogregoire on 16 Feb 2009 at 2:04

GoogleCodeExporter commented 9 years ago

Original comment by limpbizkit on 26 Apr 2009 at 9:12