Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4404195

JDI spec: Field.type() Method.returnType() is not explicit for array fields

XMLWordPrintable

    • generic
    • generic



      Name: elR10090 Date: 01/11/2001



      The specification for the method Field.type() given below
      is undefined for array fields:

          public Type type() throws ClassNotLoadedException
          Returns the type of the this Field. For primitive fields, an
          appropriate PrimitiveType is always returned. For object fields,
          the appropriate ReferenceType is returned if it has been loaded
          through the enclosing type's (that is, the type returned by
          TypeComponent#enclosingType) class loader.

      1. Specification implicitly implies that method Field.type() throws
         ClassNotLoadedException for each field of array type.

         According to The Java Virtual Machine Specification Second
         Edition (5.3):
         'Array classes do not have an external binary representation;
         they are created by the Java virtual machine rather than by a
         class loader.'
         Therefore, ReferenceType is not loaded by a class loader if it
         is an array. This implies that method Field.type() must throw
         ClassNotLoadedException for each field of array of primitive
         or reference type.
         
      If ClassNotLoadedException is not thrown on any array field, returned
      Type is still undefined.

      2. TypeComponent#enclosingType is undefined in specification.

         4399657: JDI: Field.type() spec refers to undefined
      TypeComponent#enclosingType
         
         So both enclosing type and enclosing type's class loader are undefined.
         This problem is concerned not only for fields of array types, but for
         all reference type fields.

      3. Term 'apropriate ReferenceType' is not clear, because in some cases
         ReferenceType logicaly could be one of several Type's.
         
            a). If a field is an array of a primitive type (boolean), apropriate
                ReferenceType is undefined. It could be java.lang.Boolean, or
                boolean[].class, or Boolean[].class.
            b). If a field is an array of a reference type (T), apropriate
                ReferenceType is not defined also. It could be T, or T[].class.
         
      So, I believe that specification for Field.type() needs clarification --
      especially in the case when the field is an array. Probably, it would be
      more convenient to specify this case separately from other simpler cases
      when the field is scalar of primitive or reference type.

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

            rfield Robert Field (Inactive)
            latkinsunw Latkin Latkin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: