---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 20 Edition"
java_version: 20
chapter: "Chapter 4. The class File Format"
section: "4.7.26"
heading: "4.7.26. The ModulePackages Attribute"
parent: "4.7. Attributes"
source: https://docs.oracle.com/javase/specs/jvms/se20/html/jvms-4.html#jvms-4.7.26
id: "4.7.26"
url: https://jvm.obfuscated.software/jvms/se20/4.7.26.html
raw: https://jvm.obfuscated.software/jvms/se20/4.7.26.md
---

# 4.7.26. The `ModulePackages` Attribute

The `ModulePackages` attribute is a variable-length attribute in the `attributes` table of a `ClassFile` structure ([§4.1](4.1.md)). The `ModulePackages` attribute indicates all the packages of a module that are exported or opened by the `Module` attribute, as well as all the packages of the service implementations recorded in the `Module` attribute. The `ModulePackages` attribute may also indicate packages in the module that are neither exported nor opened nor contain service implementations.

There may be at most one `ModulePackages` attribute in the `attributes` table of a `ClassFile` structure.

The `ModulePackages` attribute has the following format:

```
ModulePackages_attribute {
    u2 attribute_name_index;
    u4 attribute_length;
    u2 package_count;
    u2 package_index[package_count];
}
```

The items of the `ModulePackages_attribute` structure are as follows:

- **attribute_name_index**

  The value of the `attribute_name_index` item must be a valid index into the `constant_pool` table. The `constant_pool` entry at that index must be a `CONSTANT_Utf8_info` structure ([§4.4.7](4.4.7.md)) representing the string "`ModulePackages`".

- **attribute_length**

  The value of the `attribute_length` item indicates the length of the attribute, excluding the initial six bytes.

- **package_count**

  The value of the `package_count` item indicates the number of entries in the `package_index` table.

- **package_index[]**

  The value of each entry in the `package_index` table must be a valid index into the `constant_pool` table. The `constant_pool` entry at that index must be a `CONSTANT_Package_info` structure ([§4.4.12](4.4.12.md)) representing a package in the current module.

  At most one entry in the `package_index` table may specify a package of a given name.
