Class file attributes
Everything in a class file beyond names and flags is an attribute: the bytecode itself, line numbers, generics, annotations, inner classes, records. These are the 30 the specification defines.
An attribute is a name (a Utf8 constant), a four-byte length and that many bytes. Classes, fields, methods, Code attributes and record components each carry a list of them. A JVM must skip attributes it does not recognise, which is how the format grows: new attributes are invisible to older readers.
Needed to run the class
The JVM itself reads these seven to load, verify and execute code.
| Attribute | On | Since | In java.base | What it is |
|---|---|---|---|---|
Code | method | Java 1.0 | 61,673 | The method's bytecode and everything the JVM needs to run it: how big to make the frame (max_stack and max_locals), the instructions, and the exception table that says which handler catches what over which range.. |
StackMapTable | Code | Java 6 | 23,998 | The types in each local variable and on the operand stack at every branch target and handler. |
ConstantValue | field | Java 1.0 | 5,773 | The value of a static final field of primitive or String type whose initialiser is a compile-time constant. |
NestHost | class | Java 11 | 4,016 | Names this class's nest host, the top-level class it is nested in. |
NestMembers | class | Java 11 | 969 | On the nest host, the list of its nest members. |
PermittedSubclasses | class | Java 17 | 400 | The classes allowed to extend a sealed class or implement a sealed interface. |
BootstrapMethods | class | Java 7 | 651 | The bootstrap methods that link invokedynamic call sites and compute Dynamic constants, each a MethodHandle with a list of static arguments from the constant pool.. |
For libraries, compilers and tools
The JVM ignores these, but reflection, compilers, debuggers and the module system read them.
| Attribute | On | Since | In java.base | What it is |
|---|---|---|---|---|
Exceptions | method | Java 1.0 | 8,427 | The checked exceptions a method declares. |
InnerClasses | class | Java 1.1 | 5,544 | Nested classes did not exist in Java 1.0, and the JVM still knows nothing about them: Outer$Inner is an ordinary top-level class to the JVM. |
EnclosingMethod | class | Java 5 | 689 | For a local or anonymous class, the class and method it is written in. |
Record | class | Java 16 | 190 | The components of a record, in order, each with its own attributes (Signature, annotations). |
Signature | class, field, method, record component | Java 5 | 14,866 | The generic type that the descriptor erases: a field declared List<String> has the descriptor Ljava/util/List; and the signature Ljava/util/List<Ljava/lang/String;>;. |
SourceFile | class | Java 1.0 | 7,382 | The name of the source file, which stack traces print next to the line number.. |
LineNumberTable | Code | Java 1.0 | 61,100 | Maps bytecode offsets to source lines, for stack traces and debuggers. |
LocalVariableTable | Code | Java 1.0 | 57,952 | The names and types of local variables, by slot and by range of code. |
LocalVariableTypeTable | Code | Java 5 | 12,446 | The generic signatures of local variables whose types are generic, alongside LocalVariableTable, which has only the erased descriptors.. |
MethodParameters | method | Java 8 | 2,977 | Parameter names and flags, for reflection: Parameter.getName() returns the real name only when this attribute is present, and arg0, arg1 otherwise. |
Deprecated | class, field, method | Java 1.1 | 315 | Marks a deprecated declaration. |
Synthetic | class, field, method | Java 1.1 | 0 | Marks a member the compiler generated that does not appear in the source. |
RuntimeVisibleAnnotations | class, field, method, record component | Java 5 | 4,093 | Annotations that reflection can see (getAnnotations()). |
RuntimeInvisibleAnnotations | class, field, method, record component | Java 5 | 26 | Annotations kept in the class file but hidden from reflection: the default retention. |
RuntimeVisibleParameterAnnotations | method | Java 5 | 7 | Runtime-visible annotations on each parameter of a method, as in @PathVariable("id") String id.. |
RuntimeInvisibleParameterAnnotations | method | Java 5 | 0 | Class-retention annotations on each parameter.. |
RuntimeVisibleTypeAnnotations | class, field, method, Code, record component | Java 8 | 6 | Annotations on uses of types (Java 8): @NonNull String, List<@NonNull String>, a cast, a throws clause. |
RuntimeInvisibleTypeAnnotations | class, field, method, Code, record component | Java 8 | 0 | Type annotations with class retention: what checkers such as the Checker Framework read.. |
AnnotationDefault | method | Java 5 | 6 | The default value of an annotation interface's element: String value() default "none"; compiles to an abstract method with this attribute.. |
Module | class | Java 9 | 1 | The module declaration: its name, and everything it requires, exports, opens, uses and provides. |
ModulePackages | class | Java 9 | 1 | Every package in the module, including those it does not export, so the module system does not have to scan the module's contents.. |
ModuleMainClass | class | Java 9 | 0 | The module's main class, which java --module name runs when no class is given.. |
SourceDebugExtension | class | Java 5 | 0 | Free-form debugging text, in practice a source map (JSR 45 "SMAP") from bytecode lines back to a different source language: JSP pages, and Kotlin's inline functions.. |
Also found in java.base, outside the specification: ModuleHashes (1), ModuleTarget (1). The JDK's tools add them to module-info.class.
Specification: JVMS §4.7, Attributes.