[picocontainer-scm] [jira] Commented: (PICO-382) CollectionComponentParameter having trouble with GenericArrayType

"Paul Hammant (JIRA)" <jira-yCVjj/[email protected]> Tue, 1 Nov 2011 06:28:51 -0500 (CDT)
Newsgroups gmane.comp.java.picocontainer.cvs
Message-ID <892513906.5333.1320146931143.JavaMail.j2ee-jira@codehaus01-new.managed.contegix.com>
    [ https://jira.codehaus.org/browse/PICO-382?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=282504#comment-282504 ] 

Paul Hammant commented on PICO-382:
-----------------------------------

Hi Chris, thanks for all the investigation. I'll get round to consuming this today.  I'd been backlogged for a few days with a change to 'unsatisfied' exception throwing in Pico and an inability to use IntelliJ (Codehaus license ran out).

> CollectionComponentParameter having trouble with GenericArrayType
> -----------------------------------------------------------------
>
>                 Key: PICO-382
>                 URL: https://jira.codehaus.org/browse/PICO-382
>             Project: PicoContainer
>          Issue Type: Bug
>    Affects Versions: 3.0
>            Reporter: Michael Rimov
>         Attachments: patch.txt, TestWildcardTypesInPico.java
>
>
> The following test case will throw IllegalArgumentException from CollectionComponentParameter.getCollectionType(Type)
> I tried changing the code to:
> {code}
>         if (expectedType instanceof Class) {
>             return getCollectionType((Class) expectedType);
>         } else if (expectedType instanceof ParameterizedType) {
>             ParameterizedType type = (ParameterizedType) expectedType;
>             return getCollectionType(type.getRawType());
>         } else if (expectedType instanceof GenericArrayType) {
>         	return getCollectionType( ((GenericArrayType)expectedType).getGenericComponentType());
>         }
> {code}
> but that wouldn't resolve the collection type and my understanding of the JDK 1.5 Type system is so low that I'm shooting in the dark.  Paul, do you have any ideas how to fix this?  (Or is my test case wrong usage?)
> {code}
> public class GenericArrayTestCase {
> 	public static interface GenericInterface<T> {
> 		
> 	}
> 	
> 	public static class GenericOne implements GenericInterface<String>{
> 		
> 	}
> 	
> 	public static class GenericReceiver {
> 		public final GenericInterface<?>[] items;
> 		public GenericReceiver(GenericInterface<?>[] items) {
> 			this.items = items;
> 			
> 		}
> 	}
> 	
> 	@Test
> 	public void testArraysWithGenericArguments() {
> 		MutablePicoContainer pico = new PicoBuilder().withCaching().build();
> 		
> 		pico.addComponent("one", GenericOne.class)
> 			.addComponent("two", GenericOne.class)
> 			.addComponent(GenericReceiver.class, GenericReceiver.class, new CollectionComponentParameter(false));
> 		
> 		GenericReceiver receiver = pico.getComponent(GenericReceiver.class);
> 		assertEquals(2, receiver.items.length);
> 	}
> }
> {code}

--
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>