-
Bug
-
Resolution: Unresolved
-
P4
-
21
The Module, ModulePackages, and ModuleMainClass attributes are specified to appear at most once "in the attributes table of a ClassFile structure". There is no distinction made between ClassFile structures that define modules and ClassFile structures that define classes/interfaces.
In practice, HotSpot treats a Module, ModulePackages, or ModuleMainClass attribute appearing on a class or interface declaration as a "non-predefined" attribute and ignores its contents.
This means that, e.g., within the Module attribute, a 'requires_index' pointing to a CONSTANT_Class is considered invalid when the attribute is attached to a module, but is ignored when the attribute is attached to a class or interface. HotSpot even allows multiple Module attributes to appear on a class or interface.
This sort of flag-dependent categorization of attributes (as determined by ACC_MODULE and ACC_INTERFACE) is not supported by 4.7, and envisions a finer-grained distinction between predefined and non-predefined attributes than the specification is equipped to handle. Of course, we can make a special-case rule, but the added complexity does not seem justified.
A class or interface declared with one of these attributes is extremely unlikely to appear outside of conformance tests, and if it did, that would indicate a bug that the creator of the class file would benefit from having flagged by class loading.
Proposed change: or class or interface with one of these attributes violates format checking, and should fail to load.
In practice, HotSpot treats a Module, ModulePackages, or ModuleMainClass attribute appearing on a class or interface declaration as a "non-predefined" attribute and ignores its contents.
This means that, e.g., within the Module attribute, a 'requires_index' pointing to a CONSTANT_Class is considered invalid when the attribute is attached to a module, but is ignored when the attribute is attached to a class or interface. HotSpot even allows multiple Module attributes to appear on a class or interface.
This sort of flag-dependent categorization of attributes (as determined by ACC_MODULE and ACC_INTERFACE) is not supported by 4.7, and envisions a finer-grained distinction between predefined and non-predefined attributes than the specification is equipped to handle. Of course, we can make a special-case rule, but the added complexity does not seem justified.
A class or interface declared with one of these attributes is extremely unlikely to appear outside of conformance tests, and if it did, that would indicate a bug that the creator of the class file would benefit from having flagged by class loading.
Proposed change: or class or interface with one of these attributes violates format checking, and should fail to load.
- relates to
-
JDK-8322651 4.7.2: reject ConstantValue attributes on non-static fields
- Open
-
JDK-8233854 4.8: Clarify which checks occur during format checking
- In Progress