LineNumberTable attribute

Maps bytecode offsets to source lines, for stack traces and debuggers.

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

Layout

TypeFieldWhat it holds
u2attribute_name_indexa Utf8: "LineNumberTable"
u4attribute_lengthbytes after this field
u2line_number_table_length
{u2,u2}[…]line_number_tablestart_pc, line_number

What it is for

Maps bytecode offsets to source lines, for stack traces and debuggers. The entries mark where a line's code starts; a line can have several entries if its code is split up, as loop conditions are.

How common it is

JDK 25.0.5's java.base has 61,100 LineNumberTable attributes, in 6,827 of its 7,391 classes (61,100 on Code attributes).

A real one, byte by byte

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

OffsetBytesFieldValue
89312 bytesLineNumberTable
89300 1cattribute_name_index#28
89500 00 00 06attribute_length6
89900 01line_number_table_length1
9014 bytesline 0line 1 from @0
90100 00start_pc0
90300 01line_number1

Open in the viewer

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