PicoContainer
  1. PicoContainer
  2. PICO-382

CollectionComponentParameter having trouble with GenericArrayType

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.0
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Testcase included:
      yes
    • Number of attachments :
      2

      Description

      The following test case will throw IllegalArgumentException from CollectionComponentParameter.getCollectionType(Type)

      I tried changing the code to:

              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());
              }
      
      

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

      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);
      	}
      }
      
      1. patch.txt
        10 kB
        Chris Simmons
      2. TestWildcardTypesInPico.java
        3 kB
        Chris Simmons

        People

        • Assignee:
          Unassigned
          Reporter:
          Michael Rimov
        • Votes:
          0 Vote for this issue
          Watchers:
          1 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: