You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description of the issue: On the current trunk version (3.1.0-SNAPSHOT), using assisted injection, when you create a method in the factory interface and none of the constructors match the parameters on this method, the error message is the following:
com.google.guice.assistedprivateconstructor.SomeClass has @ AssistedInject constructors, but none of them match the parameters in method com.google.guice.assistedprivateconstructor.SomeClassFactory.create(). Unable to create AssistedInject factory.
But, in most cases, there is a constructor matching the factory method, but the author only forgot to put the @Assisted annotation on the right parameters.
I think the error message should suggest this, like:
com.google.guice.assistedprivateconstructor.SomeClass has @ AssistedInject constructors, but none of them match the parameters in method com.google.guice.assistedprivateconstructor.SomeClassFactory.create(). Unable to create AssistedInject factory. Check if have the @Assisted annotation on the right parameters.
That would make this silly mistake much more easy to realize and fix!
I used the following code to generate the message:
class SomeClass { @ AssistedInject public SomeClass(String a) {
//do nothing
}
}
From brunojcm on December 15, 2012 20:42:43
Description of the issue: On the current trunk version (3.1.0-SNAPSHOT), using assisted injection, when you create a method in the factory interface and none of the constructors match the parameters on this method, the error message is the following:
com.google.guice.assistedprivateconstructor.SomeClass has
@
AssistedInject constructors, but none of them match the parameters in method com.google.guice.assistedprivateconstructor.SomeClassFactory.create(). Unable to create AssistedInject factory.But, in most cases, there is a constructor matching the factory method, but the author only forgot to put the
@
Assisted annotation on the right parameters.I think the error message should suggest this, like:
com.google.guice.assistedprivateconstructor.SomeClass has
@
AssistedInject constructors, but none of them match the parameters in method com.google.guice.assistedprivateconstructor.SomeClassFactory.create(). Unable to create AssistedInject factory. Check if have the@
Assisted annotation on the right parameters.That would make this silly mistake much more easy to realize and fix!
I used the following code to generate the message:
class SomeClass {
@
AssistedInject public SomeClass(String a) {//do nothing
}
}
interface SomeClassFactory {
SomeClass create(String a);
}
public class Main {
public static void main(String[] args) {
Injector injector = Guice.createInjector(new AbstractModule() {
@
Overrideprotected void configure() {
install(new FactoryModuleBuilder()
.build(SomeClassFactory.class));
}
});
SomeClassFactory factory = injector.getInstance(SomeClassFactory.class);
SomeClass created = factory.create("a1");
System.out.println(created);
}
}
Original issue: http://code.google.com/p/google-guice/issues/detail?id=738
The text was updated successfully, but these errors were encountered: