[jboss-dev-forums] [Design the new POJO MicroContainer] - Re: ClassCastException for char[] MetaValue creation

scott.stark@jboss.org do-not-reply at jboss.com
Tue Aug 7 15:59:40 EDT 2007


In looking into this the type info subsystem in the container module also looks broken for primitive array types. I added a primitive char[] test and its failing due to char vs Character mismatches:


  |    public void testCharArray()
  |       throws Throwable
  |    {
  |       char[] array = {'h', 'e', 'l', 'l', 'o'};
  |       testArray(array);
  |    }
  | 
  | ...
  | 
  | junit.framework.ComparisonFailure: expected:<...C> but was:<...char>
  | 	at junit.framework.Assert.assertEquals(Assert.java:81)
  | 	at junit.framework.Assert.assertEquals(Assert.java:87)
  | 	at org.jboss.test.classinfo.test.AbstractClassInfoTest.testBasics(AbstractClassInfoTest.java:83)
  | 	at org.jboss.test.classinfo.test.ClassInfoArrayTest.testArray(ClassInfoArrayTest.java:94)
  | 	at org.jboss.test.classinfo.test.ClassInfoArrayTest.testCharArray(ClassInfoArrayTest.java:52)
  | 

I also ran across JBMICROCONT-123 which is about improving the implementation, but this is actually a bug as this method does not work at all. The depth argument to Array.newInstance is the array length, not a depth for the array dimension.

  |    public static Class getArrayClass(Class clazz, int depth)
  |    {
  |       return Array.newInstance(clazz, depth).getClass();
  |    }
  | 

This simple test in org.jboss.test.classinfo.test.ClassInfoArrayTest of getArrayClass fails because getArrayClass is returning an array of the input type, not selecting the type of the indicated array dimension:

  |    public void testArrayType()
  |    {
  |       String[] array = {"hello", "world"};
  |       TypeInfoFactory factory = getTypeInfoFactory();
  |       TypeInfo info = factory.getTypeInfo(array.getClass());
  | 
  |       TypeInfo info0 = info.getArrayType(0);
  |       assertEquals(info0.getName(), "[java.lang.String;", info0.getName());
  |    }
  | 
  | ...
  | junit.framework.ComparisonFailure: [[Ljava.lang.String; expected:<......> but was:<...[L...>
  | 	at junit.framework.Assert.assertEquals(Assert.java:81)
  | 	at org.jboss.test.classinfo.test.ClassInfoArrayTest.testArrayType(ClassInfoArrayTest.java:61)
  | 


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4071717#4071717

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4071717



More information about the jboss-dev-forums mailing list