MethodParameters attribute

Parameter names and flags, for reflection: Parameter.getName() returns the real name only when this attribute is present, and arg0, arg1 otherwise.

Appears on
method
Since
class file 52.0 (Java 8)
javac writes it
with -parameters, and for some compiler-generated parameters
Needed by the JVM
no: it is for the class libraries (reflection), compilers or tools

Layout

TypeFieldWhat it holds
u2attribute_name_indexa Utf8: "MethodParameters"
u4attribute_lengthbytes after this field
u1parameters_count
{u2,u2}[…]parametersname_index, access_flags (final, synthetic, mandated)

What it is for

Parameter names and flags, for reflection: Parameter.getName() returns the real name only when this attribute is present, and arg0, arg1 otherwise. Frameworks that bind by parameter name (Spring, Jackson) rely on javac's -parameters flag.

javac writes it without being asked when a method has parameters that the source does not show or that the language requires: the outer instance of an inner class's constructor, an enum's valueOf, bridge methods and a record's canonical constructor.

How common it is

JDK 25.0.5's java.base has 2,977 MethodParameters attributes, in 1,566 of its 7,391 classes (2,977 on methods).

A real one, byte by byte

From Bridge.class (compiled by javac 25), on method compareTo:

OffsetBytesFieldValue
119111 bytesMethodParameters
119100 37attribute_name_index#55
119300 00 00 05attribute_length5
119701parameters_count1
11984 bytesparameter 0
119800 00name_index#0
120010 00access_flags0x1000 synthetic

Open in the viewer

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