[picocontainer-scm] [jira] Commented: (PICO-375) ProviderAdapter#getComponentInstance(PicoContainer, Type) uses provider's type

"Paul Hammant (JIRA)" <jira-yCVjj/[email protected]> Wed, 3 Nov 2010 19:17:03 -0500 (CDT)
Newsgroups gmane.comp.java.picocontainer.cvs
Message-ID <22002963.2811.1288829823320.JavaMail.haus-jira@codehaus01.managed.contegix.com>
    [ http://jira.codehaus.org/browse/PICO-375?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=242031#action_242031 ] 

Paul Hammant commented on PICO-375:
-----------------------------------

In respect of the "if (injectionMethod.getReturnType().isAssignableFrom(componentImplementation) || injectionMethod.getDeclaringClass().isAssignableFrom(componentImplementation)) {" change, I can apply it and no unit tests fail, so I can't as easily object to your change in that respect.

But tell me, is there a test case that you have (or could make) that supports this case ?

> ProviderAdapter#getComponentInstance(PicoContainer, Type) uses provider's type
> ------------------------------------------------------------------------------
>
>                 Key: PICO-375
>                 URL: http://jira.codehaus.org/browse/PICO-375
>             Project: PicoContainer
>          Issue Type: Bug
>          Components: PicoContainer (Java)
>    Affects Versions: 2.11
>            Reporter: Johann Burkard
>
> I think I found a bug in PicoContainer's {{ProviderAdapter}}:
> If I use a {{Provider}}, the class of the provider is used during reinjection and not the type that's being returned by the provide method of the {{Provider}}. The corresponding lines of code are:
> {code}
>     public Object getComponentInstance(PicoContainer container, Type into) throws PicoCompositionException {
>         return new Reinjector(container).reinject(key, provider.getClass(), provider, properties, new MethodInjection(provideMethod));
>     }
> {code}
> I guess this should rather be
> {code}
>     public Object getComponentInstance(PicoContainer container, Type into) throws PicoCompositionException {
>         return new Reinjector(container).reinject(key, key, provider, properties, new MethodInjection(provideMethod));
>     }
> {code}
> Also, since ProviderAdapter takes {{Object}} and not {{Provider}}, you might want to set the {{Provider}} interface to deprecated since it's no longer needed.
> Test case!
> {code}
>     @Test
>     public void providerTest() {
>         DefaultPicoContainer container = new DefaultPicoContainer();
>         
>         ProviderAdapter adapter = new ProviderAdapter(new BlorbProvider());
>         
>         container.addAdapter(adapter);
>         
>         assertNotNull(container.getComponent(Blorb.class));
>         
>     }
>     
>     public static class BlorbProvider {
>         
>         public Blorb provide() {
>             return new Blorb();
>         }
>         
>     }
>     
>     public static class Blorb {}
> {code}
> Expected result: Returns a Blorb. Actual result: java.lang.ClassCastException: com.eaio.concurrent.DynamicBlockingQueueTest$BlorbProvider is not a com.eaio.concurrent.DynamicBlockingQueueTest$Blorb

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

<hr/>
<p>
To unsubscribe from this list please visit:
</p>
<p>
    <a href="http://xircles.codehaus.org/manage_email">http://xircles.codehaus.org/manage_email</a>