A - the attribute typepublic interface AttributeMapper<A extends Attribute<A>>
class file representation of an attribute and its API model. The attribute mapper identifies an attribute by its name, and is used to parse the class file representation into a model, and to write the model representation back to a class file. Attributes defines the mappers for predefined attributes in the JVMS and certain conventional attributes. For other attributes (JVMS 4.7.1), users can define their own AttributeMapper; classes that model those attributes should extend CustomAttribute. To read those attributes, user-defined AttributeMappers must be registered to the ClassFile.AttributeMapperOption.
| Modifier and Type | Interface | Description |
|---|---|---|
static enum |
AttributeMapper.AttributeStability |
Indicates the data dependency of the class file representation of an attribute. |
| Modifier and Type | Method | Description |
|---|---|---|
default boolean |
allowMultiple() |
Returns whether this attribute may appear more than once in one structure. |
String |
name() |
Returns the name of the attribute. |
A |
readAttribute |
Creates an Attribute instance from a class file for the Class-File API. |
AttributeMapper.AttributeStability |
stability() |
Returns the data dependency of this attribute on the class file. |
void |
writeAttribute |
Writes an Attribute instance to a class file for the Class-File API. |
String name()
A readAttribute(AttributedElement enclosing, ClassReader cf, int pos)
Attribute instance from a class file for the Class-File API. This method is called by the Class-File API to support reading of attributes. Users should never call this method.
The Class-File API makes these promises about the call to this method:
Utf8Entry for the name of the attribute is accessible with cf.readEntry(pos - 6, Utf8Entry.class), and is validated; cf.readInt(pos
- 4), and is validated to be positive and not beyond the length of the class file; AttributedElement attribute access functionalities on the enclosing model may not be accessed when this method is called, but can be accessed later by the returned attribute when it is accessible to users. The returned Attribute must fulfill these requirements:
Attribute.attributeMapper() returns this mapper; Attribute.attributeName() returns the attribute name in the class file. class file data or performing actions that may throw exceptions.enclosing - the structure in which this attribute appearscf - provides access to the class file to read frompos - the offset into the class file at which the contents of the attribute startsvoid writeAttribute(BufWriter buf, A attr)
Attribute instance to a class file for the Class-File API. This method is called by the Class-File API to support writing of attributes. Users should never call this method.
The Class-File API makes these promises about the call to this method:
attr.attributeMapper() returns this mapper; buf may already have data written, that its size may not be 0. The class file writing must fulfill these requirements:
u2 and attribute length u4 must be written to the buf; attr.attributeName() is written as if with buf.writeIndex(attr.attributeName()); buf, not including the 6 bytes used by the name and the length; attr, cannot be represented in the class file format of the attribute, an IllegalArgumentException is thrown. BufWriter.patchInt(int, int, int) can be used to update the attribute length after the attribute contents are written to the buf.buf - the BufWriter to which the attribute should be writtenattr - the attribute to writeIllegalArgumentException - if some data in the API model of the attribute is invalid for the class file formatdefault boolean allowMultiple()
If an attribute does not allow multiple instances in one structure, can be supplied to a ClassFileBuilder, and multiple instances of the attribute are supplied to the builder, the last supplied attribute appears on the built structure.
false.AttributeMapper.AttributeStability stability()
class file.class file
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/classfile/AttributeMapper.html