frjaeger220 / google-guice

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

AssistedInject issues misleading error messages for configuration errors #329

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
If I invoke:

binder.bind(factoryClass).toProvider(FactoryProvider.newFactory(factoryClass,
constructedType));

where factoryClass does not return constructedType as expected then Guice
issues this error message:

com.google.inject.ConfigurationException: Guice configuration errors:
1) A binding to java.net.URI annotated with
@com.google.inject.assistedinject.Assisted(value=) already exists on a
child injector.
  while locating java.net.URI annotated with
@com.google.inject.assistedinject.Assisted(value=)
    for parameter 1 at ConstructedType.<init>(ConstructedType.java:24)
  while locating ConstructedType

The URI parameter corresponds to the @Assisted parameter in the constructor.

Guice should ensure that factoryClass returns constructedType and fail-fast
with a clearer message if it doesn't.

Original issue reported on code.google.com by gili.tza...@gmail.com on 9 Feb 2009 at 1:14

GoogleCodeExporter commented 9 years ago

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

GoogleCodeExporter commented 9 years ago
I believe the original issue is fixed with the new FactoryModuleBuilder way of 
using
AssistedInject.  using install(new FactoryModuleBuilder().build(Factory.class));
where Factory's return type isn't bound produces an error message that says, "No
implementation for MyReturnType was bound.".  If you do something like new
FactoryModuleBuilder().implement(Foo.class, 
FooImpl.class).build(BazFactory.class);,
then you'll still get the 'No Baz was bound' (if Baz is an interface) error, 
and the
Foo/FooImpl part is just ignored.

But -- there's still some misleading errors if Factory is genericized(for 
example,
Foo.Factory<E> creates Foo<E>).  If the factory is generic & is bound using
build(Factory.class) instead of new TypeLiteral<Factory<String>>(){}, this is 
the
error message:

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

1) com.google.inject.assistedinject.FactoryModuleBuilderTest$Foo<E> cannot be 
used as
a key; It is not fully specified.

2) No implementation for
com.google.inject.assistedinject.FactoryModuleBuilderTest$Foo$Factory was bound.

Original comment by sberlin on 23 May 2010 at 12:54

GoogleCodeExporter commented 9 years ago
fixed in r1165

Original comment by sberlin on 23 May 2010 at 1:40