LocalVariableTable attribute

The names and types of local variables, by slot and by range of code.

Appears on
Code
Since
class file 45.0 (Java 1.0)
javac writes it
with -g or -g:vars only
Needed by the JVM
no: it is for the class libraries (reflection), compilers or tools

Layout

TypeFieldWhat it holds
u2attribute_name_indexa Utf8: "LocalVariableTable"
u4attribute_lengthbytes after this field
u2local_variable_table_length
{u2,u2,u2,u2,u2}[…]local_variable_tablestart_pc, length, name_index, descriptor_index, index

What it is for

The names and types of local variables, by slot and by range of code. Debuggers need it to show variables by name. javac leaves it out by default, which is why a class compiled without -g shows arg0 and local variable slots instead of names.

Parameter names for reflection come from MethodParameters, not from here.

How common it is

JDK 25.0.5's java.base has 57,952 LocalVariableTable attributes, in 6,812 of its 7,391 classes (57,952 on Code attributes).

A real one, byte by byte

From Hello.class (compiled by javac 25), on method <init>, in its Code attribute:

OffsetBytesFieldValue
90518 bytesLocalVariableTable
90500 1dattribute_name_index#29
90700 00 00 0cattribute_length12
91100 01table_length1
91310 bytesvariable 0this (slot 0)
91300 00start_pc0
91500 05length5
91700 1ename_index#30
91900 1fdescriptor_index#31
92100 00index0

Open in the viewer

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