PermittedSubclasses attribute
The classes allowed to extend a sealed class or implement a sealed interface.
- Appears on
- class
- Since
- class file 61.0 (Java 17)
- javac writes it
- for sealed classes and interfaces
- Needed by the JVM
- yes: the JVM reads it to load, verify or run the class
Layout
| Type | Field | What it holds |
|---|---|---|
u2 | attribute_name_index | a Utf8: "PermittedSubclasses" |
u4 | attribute_length | bytes after this field |
u2 | number_of_classes | |
u2[…] | classes | Class entries |
What it is for
The classes allowed to extend a sealed class or implement a sealed interface. The JVM enforces it when it loads a subclass, so a class compiled separately cannot sneak into the hierarchy.
How common it is
JDK 25.0.5's java.base has 400 PermittedSubclasses attributes, in 400 of its 7,391 classes (400 on classs).
A real one, byte by byte
From Shapes$Shape.class (compiled by javac 25), on the class:
| Offset | Bytes | Field | Value |
|---|---|---|---|
| 255 | 14 bytes | PermittedSubclasses | |
| 255 | 00 0a | attribute_name_index | #10 |
| 257 | 00 00 00 08 | attribute_length | 8 |
| 261 | 00 03 | number_of_classes | 3 |
| 263 | 00 0b | class | #11 |
| 265 | 00 0d | class | #13 |
| 267 | 00 0f | class | #15 |
Specification: JVMS §4.7, The PermittedSubclasses Attribute (Java SE 25).