JDK-6202725 : (reflect) java.lang.reflect.GenericArrayType is found where byte[].class was expected
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2004-12-01
  • Updated: 2012-09-28
  • Resolved: 2004-12-07
Related Reports
Duplicate :  
Description
The javadoc of GenericArrayType says it's a Type object for arrays whose
component type is either a parameterized type or a type variable.

The following code shows that the JRE creates GenericArrayType whose component
type is a Class object (Byte.TYPE)

The javadoc and the implementation are disagreeing with each other.

================================

import java.util.List;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.lang.reflect.ParameterizedType;

public class GenericsTest {
    public static void main(String[] args) throws Exception {
        Field f = GenericsTest.class.getField("lst");
        Type t1 = f.getGenericType();
        assert t1 instanceof ParameterizedType;
        ParameterizedType t2 = (ParameterizedType) t1;
        assert t2.getActualTypeArguments().length==1;
        Type t3 = t2.getActualTypeArguments()[0];
        assert t3==byte[].class : "expected byte[] but found "+t3.getClass();
    }

    public List<byte[]> lst;
}
==============



Comments
EVALUATION The current behavior is not ideal; but the results of the method ParameterizedType.getActualTypeArguments is properly returning a Type[]. Closing as duplicate of 5041784. ###@###.### 2004-12-07 23:02:40 GMT
07-12-2004