vipx / 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 generic methods that are fully-specified #673

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This is a follow-up to bug #329.

When I bind an AssistedInject factory as follows:

   install(new
FactoryModuleBuilder().build(RequestScopedCompletionHandlerBuilder.class));

Guice complains:

   RequestScopedCompletionHandlerBuilder cannot be used as a key; It
is not fully specified.

Here is the factory definition:

   public interface RequestScopedCompletionHandlerBuilder
   {
        <V, A> RequestScopedCompletionHandler<V, A> build(
                Class<? extends CompletionHandler<V, A>> handler);
   }

Upon further investigation I discovered that this exception is thrown if the 
return type of the factory method is generic but the factory class is not. I 
believe this error message is incorrect, meant to cover the case where the user 
tries to bind a generic factory using a non-generic Key (as mentioned in bug 
#329). This isn't the case here. The factory is fully specified, as is the Key. 
I believe Guice has all the necessary information to construct the factory.

Original issue reported on code.google.com by cow...@bbs.darktech.org on 9 Dec 2011 at 2:44

GoogleCodeExporter commented 9 years ago
This is happening because assistedinject can't handle generic types just on the 
methods of the factory.  It needs the generics to be on the entire class so it 
can fully specify it at bind time.

Original comment by sberlin on 9 Dec 2011 at 3:00