JDK-6974737 : (reflect) GenericArrayType javadoc: component type can be another GenericArrayType
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2010-08-05
  • Updated: 2025-02-08
  • Resolved: 2025-02-08
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0_18"
OpenJDK Runtime Environment (IcedTea6 1.8) (fedora-41.b18.fc13-x86_64)
OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux mattlaptop2.local 2.6.33.6-147.2.4.fc13.x86_64 #1 SMP Fri Jul 23 17:14:44 UTC 2010 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
The java.lang.reflect.GenericArrayType javadoc states, "{@code GenericArrayType} represents an array type whose component type is either a parameterized type or a type variable."  This is incorrect: the component type can also be another GenericArrayType.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the test case, and observe that a GenericArrayType can have another GenericArrayType as component type.
2. Read the java.lang.reflect.GenericArrayType javadoc comment.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The documentation lists GenericArrayType as a possible kind of component type.
ACTUAL -
The documentation does not list GenericArrayType as a possible kind of component type.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;

class Generic2DArray<T> {

  T[][] arr;

  public static void main(String[] args) {
    try {
      Field arrField = Generic2DArray.class.getDeclaredField("arr");
      GenericArrayType type = (GenericArrayType) arrField.getGenericType();
      /* The javadoc for GenericArrayType fails to mention that the component
       * type can be another GenericArrayType. */
      GenericArrayType etype = (GenericArrayType) type.getGenericComponentType();
      System.out.println(etype);
    } catch (NoSuchFieldException ex) {
      throw new AssertionError(ex);
    }
  }
}
---------- END SOURCE ----------

Comments
Will be addressed as part of 8343251.
08-02-2025

EVALUATION Should investigate.
23-07-2012