LocalVariableTypeTable attribute

The generic signatures of local variables whose types are generic, alongside LocalVariableTable, which has only the erased descriptors..

Appears on
Code
Since
class file 49.0 (Java 5)
javac writes it
with -g, for locals with generic types
Needed by the JVM
no: it is for the class libraries (reflection), compilers or tools

Layout

TypeFieldWhat it holds
u2attribute_name_indexa Utf8: "LocalVariableTypeTable"
u4attribute_lengthbytes after this field
u2local_variable_type_table_length
{u2,u2,u2,u2,u2}[…]local_variable_type_tablestart_pc, length, name_index, signature_index, index

What it is for

The generic signatures of local variables whose types are generic, alongside LocalVariableTable, which has only the erased descriptors.

How common it is

JDK 25.0.5's java.base has 12,446 LocalVariableTypeTable attributes, in 2,365 of its 7,391 classes (12,446 on Code attributes).

A real one, byte by byte

From Boxing.class (compiled by javac 25), on method sum, in its Code attribute:

OffsetBytesFieldValue
106418 bytesLocalVariableTypeTable
106400 37attribute_name_index#55
106600 00 00 0cattribute_length12
107000 01table_length1
107210 bytesvariable 0values (slot 0)
107200 00start_pc0
107400 28length40
107600 33name_index#51
107800 38signature_index#56
108000 00index0

Open in the viewer

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