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

scott.stark@jboss.org do-not-reply at jboss.com
Wed Aug 8 13:10:20 EDT 2007


"alesj" wrote : "scott.stark at jboss.org" wrote : 
  |   | 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();
  |   |   |    }
  |   |   | 
  |   | 
  | 
  | What's the deal with this one then?
  | I saw you did an assignment ping-pong. :-)
  | Do you need it fixed right away?
  | How come we didn't see this (The depth argument to Array.newInstance is the array length, not a depth for the array dimension.) before? ;-)

The question is what the getArrayClass(Class, int) method is supposed to do. If its supposed to create a Class[] from Class, then the depth argument is irrelevant, and misleading. There is no such type as Class[int length].

If its supposed to create a depth dimensional array of Class, then its broken. Based on the existing tests, it seems to be the former and it should just be:

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

In terms of JBMICROCONT-123, I don't think there is a better way to do this as I see the same logic in the jdk code. So either the blind are leading the blind and that is where we got this construct from, or there is no other way to create an array Class. 


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

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



More information about the jboss-dev-forums mailing list