RuntimeInvisibleAnnotations attribute

Annotations kept in the class file but hidden from reflection: the default retention.

Appears on
class, field, method, record component
Since
class file 49.0 (Java 5)
javac writes it
for annotations with @Retention(CLASS), the default
Needed by the JVM
no: it is for the class libraries (reflection), compilers or tools

Layout

TypeFieldWhat it holds
u2attribute_name_indexa Utf8: "RuntimeInvisibleAnnotations"
u4attribute_lengthbytes after this field
u2num_annotations
annotation[num_annotations]annotations

What it is for

Annotations kept in the class file but hidden from reflection: the default retention. Bytecode tools and annotation processors reading compiled classes can still see them.

How common it is

JDK 25.0.5's java.base has 26 RuntimeInvisibleAnnotations attributes, in 19 of its 7,391 classes (9 on methods, 13 on classs, 4 on fields).

A real one, byte by byte

From Annotations.class (compiled by javac 25), on method old:

OffsetBytesFieldValue
138212 bytesRuntimeInvisibleAnnotations
138200 2fattribute_name_index#47
138400 00 00 06attribute_length6
138800 01num_annotations1
13904 bytesannotation 0@Annotations$BuildOnly
139000 30type_index#48
139200 00num_element_value_pairs0

Open in the viewer

Specification: JVMS §4.7, The RuntimeInvisibleAnnotations Attribute (Java SE 25).