ModulePackages attribute

Every package in the module, including those it does not export, so the module system does not have to scan the module's contents..

Appears on
class
Since
class file 53.0 (Java 9)
javac writes it
not by javac; the jar tool and jlink add it
Needed by the JVM
no: it is for the class libraries (reflection), compilers or tools

Layout

TypeFieldWhat it holds
u2attribute_name_indexa Utf8: "ModulePackages"
u4attribute_lengthbytes after this field
u2package_count
u2[…]package_indexPackage entries

What it is for

Every package in the module, including those it does not export, so the module system does not have to scan the module's contents.

How common it is

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

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