Status: New
Owner: ----

New issue 738 by bruno...@gmail.com: Better message on assisted injection when there is no matching arguments on the constructor
http://code.google.com/p/google-guice/issues/detail?id=738

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() {
                        @Override
                        protected void configure() {
                                install(new FactoryModuleBuilder()
                                        .build(SomeClassFactory.class));
                        }
                });
                
                SomeClassFactory factory = 
injector.getInstance(SomeClassFactory.class);
                SomeClass created = factory.create("a1");
                System.out.println(created);
        }
}

--
You received this message because you are subscribed to the Google Groups 
"google-guice-dev" group.
To post to this group, send email to google-guice-dev@googlegroups.com.
To unsubscribe from this group, send email to 
google-guice-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-guice-dev?hl=en.

Reply via email to