RuntimeVisibleTypeAnnotations attribute

Annotations on uses of types (Java 8): @NonNull String, List<@NonNull String>, a cast, a throws clause.

Appears on
class, field, method, Code, record component
Since
class file 52.0 (Java 8)
javac writes it
for runtime-visible TYPE_USE annotations
Needed by the JVM
no: it is for the class libraries (reflection), compilers or tools

Layout

TypeFieldWhat it holds
u2attribute_name_indexa Utf8: "RuntimeVisibleTypeAnnotations"
u4attribute_lengthbytes after this field
u2num_annotations
type_annotation[…]annotationstarget_type, target_info, type_path, then the annotation

What it is for

Annotations on uses of types (Java 8): @NonNull String, List<@NonNull String>, a cast, a throws clause. Each records exactly which type use it annotates, down to a type argument or array level.

How common it is

JDK 25.0.5's java.base has 6 RuntimeVisibleTypeAnnotations attributes, in 6 of its 7,391 classes (6 on classs).

A real one, byte by byte

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

OffsetBytesFieldValue
148914 bytesRuntimeVisibleTypeAnnotations
148900 34attribute_name_index#52
149100 00 00 08attribute_length8
149500 01num_annotations1
14976 bytestype_annotation
149714target_type0x14
1498target_info
14981 bytestype_path
149800path_length0
149900 35type_index#53
150100 00num_element_value_pairs0

Open in the viewer

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