Module attribute
The module declaration: its name, and everything it requires, exports, opens, uses and provides.
- Appears on
- class
- Since
- class file 53.0 (Java 9)
- javac writes it
- for module-info.class
- Needed by the JVM
- no: it is for the class libraries (reflection), compilers or tools
Layout
| Type | Field | What it holds |
|---|---|---|
u2 | attribute_name_index | a Utf8: "Module" |
u4 | attribute_length | bytes after this field |
u2 | module_name_index | a Module |
u2 | module_flags | open, synthetic, mandated |
u2 | module_version_index | |
… | requires, exports, opens, uses, provides | each a count and a table |
What it is for
The module declaration: its name, and everything it requires, exports, opens, uses and provides. Only module-info.class has it. javac writes Module itself; the jar tool and jlink add ModulePackages, ModuleMainClass and the JDK-specific ModuleTarget and ModuleHashes.
How common it is
JDK 25.0.5's java.base has 1 Module attributes, in 1 of its 7,391 classes (1 on classs).
A real one, byte by byte
From module-info.class (compiled by javac 25), on the class:
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 188 | 42 bytes | Module | |
| 188 | 00 05 | attribute_name_index | #5 |
| 190 | 00 00 00 24 | attribute_length | 36 |
| 194 | 00 06 | module_name_index | #6 |
| 196 | 00 00 | module_flags | 0 |
| 198 | 00 00 | module_version_index | #0 |
| 200 | 00 02 | requires_count | 2 |
| 202 | 6 bytes | requires 0 | |
| 202 | 00 08 | requires_index | #8 |
| 204 | 80 00 | requires_flags | 32768 |
| 206 | 00 0a | requires_version_index | #10 |
| 208 | 6 bytes | requires 1 | |
| 208 | 00 0b | requires_index | #11 |
| 210 | 00 00 | requires_flags | 0 |
| 212 | 00 0a | requires_version_index | #10 |
| 214 | 00 01 | exports_count | 1 |
| 216 | 6 bytes | exports 0 | |
| 216 | 00 0d | exports_index | #13 |
| 218 | 00 00 | exports_flags | 0 |
| 220 | 00 00 | exports_to_count | 0 |
| 222 | 00 00 | opens_count | 0 |
| 224 | 00 01 | uses_count | 1 |
| 226 | 2 bytes | uses 0 | |
| 226 | 00 0f | uses_index | #15 |
| 228 | 00 00 | provides_count | 0 |
Specification: JVMS §4.7, The Module Attribute (Java SE 25).