[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:03:03 -0500 (CDT)
| Newsgroups | gmane.comp.java.picocontainer.cvs |
|---|---|
| Message-ID | <31528201.2806.1288828983326.JavaMail.haus-jira@codehaus01.managed.contegix.com> |
[ http://jira.codehaus.org/browse/PICO-375?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=242028#action_242028 ]
Paul Hammant commented on PICO-375:
-----------------------------------
Johann, in respect of the main issue you've filed:
I (1) tried to run the unit tests (mvn clean install) for Pico, after making the s/provider.getClass()/key change. Many tests broke (try it).
Then I (2) changed the interface to insist on ProviderAdapter having Provider (rather than Object) put into it. You've not seen, but there is plenty of "instanceof Provider" in the codebase, even though there are no methods specified on it. Its a speed issue. I don't want to scan a class speculatively for a method named provide (with differing params) as I'd have to go through every class. That said, there could be an improvement. More to follow. Addressing the main issue: change list #5743
> 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>