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.

AttributeOnSinceIn java.baseWhat it is
CodemethodJava 1.061,673The 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..
StackMapTableCodeJava 623,998The types in each local variable and on the operand stack at every branch target and handler.
ConstantValuefieldJava 1.05,773The value of a static final field of primitive or String type whose initialiser is a compile-time constant.
NestHostclassJava 114,016Names this class's nest host, the top-level class it is nested in.
NestMembersclassJava 11969On the nest host, the list of its nest members.
PermittedSubclassesclassJava 17400The classes allowed to extend a sealed class or implement a sealed interface.
BootstrapMethodsclassJava 7651The 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.

AttributeOnSinceIn java.baseWhat it is
ExceptionsmethodJava 1.08,427The checked exceptions a method declares.
InnerClassesclassJava 1.15,544Nested 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.
EnclosingMethodclassJava 5689For a local or anonymous class, the class and method it is written in.
RecordclassJava 16190The components of a record, in order, each with its own attributes (Signature, annotations).
Signatureclass, field, method, record componentJava 514,866The 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;>;.
SourceFileclassJava 1.07,382The name of the source file, which stack traces print next to the line number..
LineNumberTableCodeJava 1.061,100Maps bytecode offsets to source lines, for stack traces and debuggers.
LocalVariableTableCodeJava 1.057,952The names and types of local variables, by slot and by range of code.
LocalVariableTypeTableCodeJava 512,446The generic signatures of local variables whose types are generic, alongside LocalVariableTable, which has only the erased descriptors..
MethodParametersmethodJava 82,977Parameter names and flags, for reflection: Parameter.getName() returns the real name only when this attribute is present, and arg0, arg1 otherwise.
Deprecatedclass, field, methodJava 1.1315Marks a deprecated declaration.
Syntheticclass, field, methodJava 1.10Marks a member the compiler generated that does not appear in the source.
RuntimeVisibleAnnotationsclass, field, method, record componentJava 54,093Annotations that reflection can see (getAnnotations()).
RuntimeInvisibleAnnotationsclass, field, method, record componentJava 526Annotations kept in the class file but hidden from reflection: the default retention.
RuntimeVisibleParameterAnnotationsmethodJava 57Runtime-visible annotations on each parameter of a method, as in @PathVariable("id") String id..
RuntimeInvisibleParameterAnnotationsmethodJava 50Class-retention annotations on each parameter..
RuntimeVisibleTypeAnnotationsclass, field, method, Code, record componentJava 86Annotations on uses of types (Java 8): @NonNull String, List<@NonNull String>, a cast, a throws clause.
RuntimeInvisibleTypeAnnotationsclass, field, method, Code, record componentJava 80Type annotations with class retention: what checkers such as the Checker Framework read..
AnnotationDefaultmethodJava 56The default value of an annotation interface's element: String value() default "none"; compiles to an abstract method with this attribute..
ModuleclassJava 91The module declaration: its name, and everything it requires, exports, opens, uses and provides.
ModulePackagesclassJava 91Every package in the module, including those it does not export, so the module system does not have to scan the module's contents..
ModuleMainClassclassJava 90The module's main class, which java --module name runs when no class is given..
SourceDebugExtensionclassJava 50Free-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.