JVM Knowledge

The Record attribute is a variable-length attribute in the attributes table of a ClassFile structure (§4.1). The Record attribute indicates that the current class is a record class (JLS §8.10), and stores information about the record components of the record class (JLS §8.10.1).

There may be at most one Record attribute in the attributes table of a ClassFile structure.

The Record attribute has the following format:

Record_attribute {
    u2                    attribute_name_index;
    u4                    attribute_length;
    u2                    components_count;
    record_component_info components[components_count];
}

The items of the Record_attribute structure are as follows:

  • attribute_name_index

    The value of the attribute_name_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Utf8_info structure (§4.4.7) representing the string "Record".

  • attribute_length

    The value of the attribute_length item indicates the length of the attribute, excluding the initial six bytes.

  • components_count

    The value of the components_count item indicates the number of entries in the components table.

  • components[]

    Each entry in the components table specifies a record component of the current class, in the order the record components were declared. The record_component_info structure has the following format:

    record_component_info {
        u2             name_index;
        u2             descriptor_index;
        u2             attributes_count;
        attribute_info attributes[attributes_count];
    }
    

    The items of the record_component_info structure are as follows:

    • name_index

      The value of the name_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Utf8_info structure (§4.4.7) representing a valid unqualified name denoting the record component (§4.2.2).

    • descriptor_index

      The value of the descriptor_index item must be a valid index into the constant_pool table. The constant_pool entry at that index must be a CONSTANT_Utf8_info structure (§4.4.7) representing a field descriptor which encodes the type of the record component (§4.3.2).

    • attributes_count

      The value of the attributes_count item indicates the number of additional attributes of this record component.

    • attributes[]

      Each value of the attributes table must be an attribute_info structure (§4.7).

      A record component can have any number of optional attributes associated with it.

      The attributes defined by this specification as appearing in the attributes table of a record_component_info structure are listed in Table 4.7-C.

      The rules concerning attributes defined to appear in the attributes table of a record_component_info structure are given in §4.7.

      The rules concerning non-predefined attributes in the attributes table of a record_component_info structure are given in §4.7.1.