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

"Johann Burkard (JIRA)" <jira-yCVjj/[email protected]> Wed, 3 Nov 2010 15:42:04 -0500 (CDT)
Newsgroups gmane.comp.java.picocontainer.cvs
Message-ID <29158064.2683.1288816924715.JavaMail.haus-jira@codehaus01.managed.contegix.com>
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>