[picocontainer-scm] [jira] Created: (PICO-384) ClassCastException obtaining component from parent container when using CompositePicoContainer.

"Chris Simmons (JIRA)" <jira-yCVjj/[email protected]> Mon, 24 Oct 2011 04:37:51 -0500 (CDT)
Newsgroups gmane.comp.java.picocontainer.cvs
Message-ID <2108231380.947.1319449071119.JavaMail.j2ee-jira@codehaus01-new.managed.contegix.com>
ClassCastException obtaining component from parent container when using CompositePicoContainer.
-----------------------------------------------------------------------------------------------

                 Key: PICO-384
                 URL: https://jira.codehaus.org/browse/PICO-384
             Project: PicoContainer
          Issue Type: Bug
          Components: PicoContainer (Java)
    Affects Versions: 2.13.5
            Reporter: Chris Simmons
         Attachments: TestPicoClassCast.java

I encountered a ClassCastException when using a composite container.  I *think* I've tracked down the problem to this method:-

org.picocontainer.DefaultPicoContainer.getInstance(ComponentAdapter<?>, Class)

In this case isLocal is false and parent != null.  Its passing in the key from the component adapter rather than using the componentKey.  In this case these are different.  componentKey is Impl2 but the componentAdapter's key is AnInterface.  Subsequently the composite pico returns Impl1 and it attempts to cast it to anImpl2.

I'd guess that changing it to do this would fix this problem but perhaps it would cause other problems?

return getParent().getComponent(componentKey);


--
This message is automatically generated by JIRA.
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>