RuntimeVisibleAnnotations attribute

Annotations that reflection can see (getAnnotations()).

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

Layout

TypeFieldWhat it holds
u2attribute_name_indexa Utf8: "RuntimeVisibleAnnotations"
u4attribute_lengthbytes after this field
u2num_annotations
annotation[num_annotations]annotationstype_index, then element name and value pairs

What it is for

Annotations that reflection can see (getAnnotations()). Each one is its type as a field descriptor plus element-value pairs; values can be constants, enums, classes, nested annotations or arrays.

How common it is

JDK 25.0.5's java.base has 4,093 RuntimeVisibleAnnotations attributes, in 664 of its 7,391 classes (3,567 on methods, 220 on classs, 306 on fields).

A real one, byte by byte

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

OffsetBytesFieldValue
137012 bytesRuntimeVisibleAnnotations
137000 17attribute_name_index#23
137200 00 00 06attribute_length6
137600 01num_annotations1
13784 bytesannotation 0@java.lang.Deprecated
137800 2etype_index#46
138000 00num_element_value_pairs0

Open in the viewer

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