---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 21 Edition"
java_version: 21
chapter: "Chapter 4. The class File Format"
section: "4.7"
heading: "4.7. Attributes"
parent: "Chapter 4. The class File Format"
source: https://docs.oracle.com/javase/specs/jvms/se21/html/jvms-4.html#jvms-4.7
id: "4.7"
url: https://jvm.obfuscated.software/jvms/se21/4.7.html
raw: https://jvm.obfuscated.software/jvms/se21/4.7.md
---

# 4.7. Attributes

*Attributes* are used in the `ClassFile`, `field_info`, `method_info`, `Code_attribute`, and `record_component_info` structures of the `class` file format ([§4.1](4.1.md), [§4.5](4.5.md), [§4.6](4.6.md), [§4.7.3](4.7.3.md), [§4.7.30](4.7.30.md)).

All attributes have the following general format:

```
attribute_info {
    u2 attribute_name_index;
    u4 attribute_length;
    u1 info[attribute_length];
}
```

For all attributes, the `attribute_name_index` item must be a valid unsigned 16-bit index into the constant pool of the class. The `constant_pool` entry at `attribute_name_index` must be a `CONSTANT_Utf8_info` structure ([§4.4.7](4.4.7.md)) representing the name of the attribute. The value of the `attribute_length` item indicates the length of the subsequent information in bytes. The length does not include the initial six bytes that contain the `attribute_name_index` and `attribute_length` items.

30 attributes are predefined by this specification. They are listed three times, for ease of navigation:

- Table 4.7-A is ordered by the attributes' section numbers in this chapter. Each attribute is shown with the first version of the `class` file format in which it was defined. Also shown is the version of the Java SE Platform which introduced that version of the `class` file format ([§4.1](4.1.md)).
- Table 4.7-B is ordered by the first version of the `class` file format in which each attribute was defined.
- Table 4.7-C is ordered by the location in a `class` file where each attribute is defined to appear.

Within the context of their use in this specification, that is, in the `attributes` tables of the `class` file structures in which they appear, the names of these predefined attributes are reserved.

Any conditions on the presence of a predefined attribute in an `attributes` table are specified explicitly in the section which describes the attribute. If no conditions are specified, then the attribute may appear any number of times in an `attributes` table.

The predefined attributes are categorized into three groups according to their purpose:

1. Seven attributes are critical to correct interpretation of the `class` file by the Java Virtual Machine:

   - `ConstantValue`
   - `Code`
   - `StackMapTable`
   - `BootstrapMethods`
   - `NestHost`
   - `NestMembers`
   - `PermittedSubclasses`

   In a `class` file whose version number is *v*, each of these attributes must be recognized and correctly read by an implementation of the Java Virtual Machine if the implementation supports version *v* of the `class` file format, and the attribute was first defined in version *v* or earlier of the `class` file format, and the attribute appears in a location where it is defined to appear.

2. Ten attributes are not critical to correct interpretation of the `class` file by the Java Virtual Machine, but are either critical to correct interpretation of the `class` file by the class libraries of the Java SE Platform, or are useful for tools (in which case the section that specifies an attribute describes it as "optional"):

   - `Exceptions`
   - `InnerClasses`
   - `EnclosingMethod`
   - `Synthetic`
   - `Signature`
   - `Record`
   - `SourceFile`
   - `LineNumberTable`
   - `LocalVariableTable`
   - `LocalVariableTypeTable`

   In a `class` file whose version number is *v*, each of these attributes must be recognized and correctly read by an implementation of the Java Virtual Machine if the implementation supports version *v* of the `class` file format, and the attribute was first defined in version *v* or earlier of the `class` file format, and the attribute appears in a location where it is defined to appear.

3. Thirteen attributes are not critical to correct interpretation of the `class` file by the Java Virtual Machine, but contain metadata about the `class` file that is either exposed by the class libraries of the Java SE Platform, or made available by tools (in which case the section that specifies an attribute describes it as "optional"):

   - `SourceDebugExtension`
   - `Deprecated`
   - `RuntimeVisibleAnnotations`
   - `RuntimeInvisibleAnnotations`
   - `RuntimeVisibleParameterAnnotations`
   - `RuntimeInvisibleParameterAnnotations`
   - `RuntimeVisibleTypeAnnotations`
   - `RuntimeInvisibleTypeAnnotations`
   - `AnnotationDefault`
   - `MethodParameters`
   - `Module`
   - `ModulePackages`
   - `ModuleMainClass`

   An implementation of the Java Virtual Machine may use the information that these attributes contain, or otherwise must silently ignore these attributes.

**Table 4.7-A. Predefined `class` file attributes (by section)**

| Attribute | Section | `class` file | Java SE |
|---|---|---|---|
| `ConstantValue` | [§4.7.2](4.7.2.md) | 45.3 | 1.0.2 |
| `Code` | [§4.7.3](4.7.3.md) | 45.3 | 1.0.2 |
| `StackMapTable` | [§4.7.4](4.7.4.md) | 50.0 | 6 |
| `Exceptions` | [§4.7.5](4.7.5.md) | 45.3 | 1.0.2 |
| `InnerClasses` | [§4.7.6](4.7.6.md) | 45.3 | 1.1 |
| `EnclosingMethod` | [§4.7.7](4.7.7.md) | 49.0 | 5.0 |
| `Synthetic` | [§4.7.8](4.7.8.md) | 45.3 | 1.1 |
| `Signature` | [§4.7.9](4.7.9.md) | 49.0 | 5.0 |
| `SourceFile` | [§4.7.10](4.7.10.md) | 45.3 | 1.0.2 |
| `SourceDebugExtension` | [§4.7.11](4.7.11.md) | 49.0 | 5.0 |
| `LineNumberTable` | [§4.7.12](4.7.12.md) | 45.3 | 1.0.2 |
| `LocalVariableTable` | [§4.7.13](4.7.13.md) | 45.3 | 1.0.2 |
| `LocalVariableTypeTable` | [§4.7.14](4.7.14.md) | 49.0 | 5.0 |
| `Deprecated` | [§4.7.15](4.7.15.md) | 45.3 | 1.1 |
| `RuntimeVisibleAnnotations` | [§4.7.16](4.7.16.md) | 49.0 | 5.0 |
| `RuntimeInvisibleAnnotations` | [§4.7.17](4.7.17.md) | 49.0 | 5.0 |
| `RuntimeVisibleParameterAnnotations` | [§4.7.18](4.7.18.md) | 49.0 | 5.0 |
| `RuntimeInvisibleParameterAnnotations` | [§4.7.19](4.7.19.md) | 49.0 | 5.0 |
| `RuntimeVisibleTypeAnnotations` | [§4.7.20](4.7.20.md) | 52.0 | 8 |
| `RuntimeInvisibleTypeAnnotations` | [§4.7.21](4.7.21.md) | 52.0 | 8 |
| `AnnotationDefault` | [§4.7.22](4.7.22.md) | 49.0 | 5.0 |
| `BootstrapMethods` | [§4.7.23](4.7.23.md) | 51.0 | 7 |
| `MethodParameters` | [§4.7.24](4.7.24.md) | 52.0 | 8 |
| `Module` | [§4.7.25](4.7.25.md) | 53.0 | 9 |
| `ModulePackages` | [§4.7.26](4.7.26.md) | 53.0 | 9 |
| `ModuleMainClass` | [§4.7.27](4.7.27.md) | 53.0 | 9 |
| `NestHost` | [§4.7.28](4.7.28.md) | 55.0 | 11 |
| `NestMembers` | [§4.7.29](4.7.29.md) | 55.0 | 11 |
| `Record` | [§4.7.30](4.7.30.md) | 60.0 | 16 |
| `PermittedSubclasses` | [§4.7.31](4.7.31.md) | 61.0 | 17 |

**Table 4.7-B. Predefined `class` file attributes (by `class` file format)**

| Attribute | `class` file | Java SE | Section |
|---|---|---|---|
| `ConstantValue` | 45.3 | 1.0.2 | [§4.7.2](4.7.2.md) |
| `Code` | 45.3 | 1.0.2 | [§4.7.3](4.7.3.md) |
| `Exceptions` | 45.3 | 1.0.2 | [§4.7.5](4.7.5.md) |
| `SourceFile` | 45.3 | 1.0.2 | [§4.7.10](4.7.10.md) |
| `LineNumberTable` | 45.3 | 1.0.2 | [§4.7.12](4.7.12.md) |
| `LocalVariableTable` | 45.3 | 1.0.2 | [§4.7.13](4.7.13.md) |
| `InnerClasses` | 45.3 | 1.1 | [§4.7.6](4.7.6.md) |
| `Synthetic` | 45.3 | 1.1 | [§4.7.8](4.7.8.md) |
| `Deprecated` | 45.3 | 1.1 | [§4.7.15](4.7.15.md) |
| `EnclosingMethod` | 49.0 | 5.0 | [§4.7.7](4.7.7.md) |
| `Signature` | 49.0 | 5.0 | [§4.7.9](4.7.9.md) |
| `SourceDebugExtension` | 49.0 | 5.0 | [§4.7.11](4.7.11.md) |
| `LocalVariableTypeTable` | 49.0 | 5.0 | [§4.7.14](4.7.14.md) |
| `RuntimeVisibleAnnotations` | 49.0 | 5.0 | [§4.7.16](4.7.16.md) |
| `RuntimeInvisibleAnnotations` | 49.0 | 5.0 | [§4.7.17](4.7.17.md) |
| `RuntimeVisibleParameterAnnotations` | 49.0 | 5.0 | [§4.7.18](4.7.18.md) |
| `RuntimeInvisibleParameterAnnotations` | 49.0 | 5.0 | [§4.7.19](4.7.19.md) |
| `AnnotationDefault` | 49.0 | 5.0 | [§4.7.22](4.7.22.md) |
| `StackMapTable` | 50.0 | 6 | [§4.7.4](4.7.4.md) |
| `BootstrapMethods` | 51.0 | 7 | [§4.7.23](4.7.23.md) |
| `RuntimeVisibleTypeAnnotations` | 52.0 | 8 | [§4.7.20](4.7.20.md) |
| `RuntimeInvisibleTypeAnnotations` | 52.0 | 8 | [§4.7.21](4.7.21.md) |
| `MethodParameters` | 52.0 | 8 | [§4.7.24](4.7.24.md) |
| `Module` | 53.0 | 9 | [§4.7.25](4.7.25.md) |
| `ModulePackages` | 53.0 | 9 | [§4.7.26](4.7.26.md) |
| `ModuleMainClass` | 53.0 | 9 | [§4.7.27](4.7.27.md) |
| `NestHost` | 55.0 | 11 | [§4.7.28](4.7.28.md) |
| `NestMembers` | 55.0 | 11 | [§4.7.29](4.7.29.md) |
| `Record` | 60.0 | 16 | [§4.7.30](4.7.30.md) |
| `PermittedSubclasses` | 61.0 | 17 | [§4.7.31](4.7.31.md) |

**Table 4.7-C. Predefined `class` file attributes (by location)**

| Attribute | Location | `class` file |
|---|---|---|
| `SourceFile` | `ClassFile` | 45.3 |
| `InnerClasses` | `ClassFile` | 45.3 |
| `EnclosingMethod` | `ClassFile` | 49.0 |
| `SourceDebugExtension` | `ClassFile` | 49.0 |
| `BootstrapMethods` | `ClassFile` | 51.0 |
| `Module`, `ModulePackages`, `ModuleMainClass` | `ClassFile` | 53.0 |
| `NestHost`, `NestMembers` | `ClassFile` | 55.0 |
| `Record` | `ClassFile` | 60.0 |
| `PermittedSubclasses` | `ClassFile` | 61.0 |
| `ConstantValue` | `field_info` | 45.3 |
| `Code` | `method_info` | 45.3 |
| `Exceptions` | `method_info` | 45.3 |
| `RuntimeVisibleParameterAnnotations`, `RuntimeInvisibleParameterAnnotations` | `method_info` | 49.0 |
| `AnnotationDefault` | `method_info` | 49.0 |
| `MethodParameters` | `method_info` | 52.0 |

**Table 4.7-C (cont.). Predefined `class` file attributes (by location)**

| Attribute | Location | `class` file |
|---|---|---|
| `Synthetic` | `ClassFile`, `field_info`, `method_info` | 45.3 |
| `Deprecated` | `ClassFile`, `field_info`, `method_info` | 45.3 |
| `Signature` | `ClassFile`, `field_info`, `method_info`, `record_component_info` | 49.0 |
| `RuntimeVisibleAnnotations`, `RuntimeInvisibleAnnotations` | `ClassFile`, `field_info`, `method_info`, `record_component_info` | 49.0 |
| `LineNumberTable` | `Code` | 45.3 |
| `LocalVariableTable` | `Code` | 45.3 |
| `LocalVariableTypeTable` | `Code` | 49.0 |
| `StackMapTable` | `Code` | 50.0 |
| `RuntimeVisibleTypeAnnotations`, `RuntimeInvisibleTypeAnnotations` | `ClassFile`, `field_info`, `method_info`, `Code`, `record_component_info` | 52.0 |

**Sections:**

- [4.7.1. Defining and Naming New Attributes](4.7.1.md)
- [4.7.2. The ConstantValue Attribute](4.7.2.md)
- [4.7.3. The Code Attribute](4.7.3.md)
- [4.7.4. The StackMapTable Attribute](4.7.4.md)
- [4.7.5. The Exceptions Attribute](4.7.5.md)
- [4.7.6. The InnerClasses Attribute](4.7.6.md)
- [4.7.7. The EnclosingMethod Attribute](4.7.7.md)
- [4.7.8. The Synthetic Attribute](4.7.8.md)
- [4.7.9. The Signature Attribute](4.7.9.md)
- [4.7.10. The SourceFile Attribute](4.7.10.md)
- [4.7.11. The SourceDebugExtension Attribute](4.7.11.md)
- [4.7.12. The LineNumberTable Attribute](4.7.12.md)
- [4.7.13. The LocalVariableTable Attribute](4.7.13.md)
- [4.7.14. The LocalVariableTypeTable Attribute](4.7.14.md)
- [4.7.15. The Deprecated Attribute](4.7.15.md)
- [4.7.16. The RuntimeVisibleAnnotations Attribute](4.7.16.md)
- [4.7.17. The RuntimeInvisibleAnnotations Attribute](4.7.17.md)
- [4.7.18. The RuntimeVisibleParameterAnnotations Attribute](4.7.18.md)
- [4.7.19. The RuntimeInvisibleParameterAnnotations Attribute](4.7.19.md)
- [4.7.20. The RuntimeVisibleTypeAnnotations Attribute](4.7.20.md)
- [4.7.21. The RuntimeInvisibleTypeAnnotations Attribute](4.7.21.md)
- [4.7.22. The AnnotationDefault Attribute](4.7.22.md)
- [4.7.23. The BootstrapMethods Attribute](4.7.23.md)
- [4.7.24. The MethodParameters Attribute](4.7.24.md)
- [4.7.25. The Module Attribute](4.7.25.md)
- [4.7.26. The ModulePackages Attribute](4.7.26.md)
- [4.7.27. The ModuleMainClass Attribute](4.7.27.md)
- [4.7.28. The NestHost Attribute](4.7.28.md)
- [4.7.29. The NestMembers Attribute](4.7.29.md)
- [4.7.30. The Record Attribute](4.7.30.md)
- [4.7.31. The PermittedSubclasses Attribute](4.7.31.md)
