xiaodududu / google-guice

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

Better error reports for Assistedinject where source class is not an interface #590

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I recently attempted something which I think turns out not to be supported by 
assisted injection. However, the error report was fairly obscure and could have 
been clearer.

I was attempting to inject a ServletContextHandler differently in different 
modules, using FactoryBuilder to dynamically provision factories for subclasses 
of ServletContextHandler. These subclasses offered constructors annotated with 
@Assisted, and the correct parameters were available in the Factory interface 
definition.

However it turns out that org.eclipse.jetty.servlet ServletContextHandler is a 
concrete superclass and not an interface.

However, rather than complaining that ServletContextHandler is not an 
interface, Guice warned me that no appropriate constructor could be found. I 
therefore spent quite some time trying to ensure the constructor was properly 
visible and trying many combinations to satisfy the injector. However, the 
Injector could tell immediately that the source class was not an interface.

Reading the documentation I finally I came to the conclusion that 
FactoryBuilder is unable to dynamically provision a factory unless the return 
value satisfies the signature of an interface, but if this was warned right 
from the beginning it would be helpful.

Original issue reported on code.google.com by c...@cefn.com on 17 Jan 2011 at 3:51

GoogleCodeExporter commented 9 years ago
The factory itself has to be an interface -- the return values of methods in 
the factory can be classes though.  I'm not sure which one you're talking about 
here.  Can you add a testcase that reproduces the problem you're seeing?

Original comment by sberlin on 18 Jan 2011 at 5:53

GoogleCodeExporter commented 9 years ago

Original comment by sberlin on 19 Feb 2011 at 8:20