Class Attribute
- Direct Known Subclasses:
AnnotationDefault, Annotations, BootstrapMethods, Code, ConstantValue, Deprecated, EnclosingMethod, ExceptionTable, InnerClasses, LineNumberTable, LocalVariableTable, LocalVariableTypeTable, MethodParameters, Module, ModuleMainClass, ModulePackages, NestHost, NestMembers, ParameterAnnotations, PermittedSubclasses, PMGClass, Record, Signature, SourceFile, StackMap, Synthetic, TypeAnnotations, Unknown
attribute_info {
u2 attribute_name_index;
u4 attribute_length;
u1 info[attribute_length];
}
The default maximum number of attribute nesting levels in readAttribute(DataInput, ConstantPool) is 64 before throwing a
ClassFormatException. This is configurable through the system property org.apache.bcel.classfile.Attribute.maxNestingDepth. Attributes may
legitimately nest (for example, a Code attribute carries its own attribute table, and Record components carry theirs), but a malicious
class file can nest such attributes deeply enough to overflow the parser's stack.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ConstantPoolDeprecated.(since 6.0) will be made private; do not access directly, use getter/setter.static final Attribute[]Empty array.protected intDeprecated.(since 6.0) (since 6.0) will be made private; do not access directly, use getter/setter.protected intDeprecated.(since 6.0) will be made private; do not access directly, use getter/setter.protected byteDeprecated.(since 6.0) will be made private; do not access directly, use getter/setter. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAttribute(byte tag, int nameIndex, int length, ConstantPool constantPool) Constructs an instance. -
Method Summary
Modifier and TypeMethodDescriptionabstract voidCalled by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class.static voidaddAttributeReader(String name, AttributeReader attributeReader) Deprecated.(6.0) UseaddAttributeReader(String, UnknownAttributeReader)instead.static voidaddAttributeReader(String name, UnknownAttributeReader unknownAttributeReader) Add an Attribute reader capable of parsing (user-defined) attributes named "name".clone()Use copy() if you want to have a deep copy(), that is, with all references copied correctly.abstract Attributecopy(ConstantPool constantPool) Creates a deep copy of this attribute.voiddump(DataOutputStream file) Dumps attribute to file stream in binary format.final ConstantPoolGets the constant pool used by this object.final intGets the length of attribute field in bytes.getName()Gets the name of the attribute.final intGets the name index in constant pool of attribute name.final bytegetTag()Gets the tag of attribute, that is, its type.protected static voidPrints a message to stderr if debug mode is enabled.static AttributereadAttribute(DataInput dataInput, ConstantPool constantPool) Reads one attribute using standard eight-byte Code headers.static AttributereadAttribute(DataInput dataInput, ConstantPool constantPool, boolean compactCodeHeader) Reads one attribute using the selected Code header layout.static AttributereadAttribute(DataInputStream dataInputStream, ConstantPool constantPool) Reads one attribute using standard eight-byte Code headers.static voidremoveAttributeReader(String name) Remove attribute readerfinal voidsetConstantPool(ConstantPool constantPool) Sets the constant pool to be used for this object.final voidsetLength(int length) Sets the length in bytes.final voidsetNameIndex(int nameIndex) Sets the name index of attribute.toString()
-
Field Details
-
EMPTY_ARRAY
-
name_index
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter. -
length
Deprecated.(since 6.0) (since 6.0) will be made private; do not access directly, use getter/setter. -
tag
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter. -
constant_pool
Deprecated.(since 6.0) will be made private; do not access directly, use getter/setter.
-
-
Constructor Details
-
Attribute
Constructs an instance.attribute_info { u2 attribute_name_index; u4 attribute_length; u1 info[attribute_length]; }- Parameters:
tag- tag.nameIndex- u2 name index.length- u4 length.constantPool- constant pool.
-
-
Method Details
-
addAttributeReader
Deprecated.(6.0) UseaddAttributeReader(String, UnknownAttributeReader)instead.Add an Attribute reader capable of parsing (user-defined) attributes named "name". You should not add readers for the standard attributes such as "LineNumberTable", because those are handled internally.- Parameters:
name- The name of the attribute as stored in the class file.attributeReader- The reader object.
-
addAttributeReader
Add an Attribute reader capable of parsing (user-defined) attributes named "name". You should not add readers for the standard attributes such as "LineNumberTable", because those are handled internally.- Parameters:
name- The name of the attribute as stored in the class file.unknownAttributeReader- The reader object.
-
println
-
readAttribute
public static Attribute readAttribute(DataInput dataInput, ConstantPool constantPool) throws IOException Reads one attribute using standard eight-byte Code headers.- Parameters:
dataInput- Input stream.constantPool- Array of constants.- Returns:
- Attribute.
- Throws:
IOException- Thrown if an I/O error occurs.- Since:
- 6.0
- See Also:
-
readAttribute
public static Attribute readAttribute(DataInput dataInput, ConstantPool constantPool, boolean compactCodeHeader) throws IOException Reads one attribute using the selected Code header layout.The compact layout uses
u1,u1, andu2formax_stack,max_locals, andcode_length, respectively. These fields occupy 4 bytes instead of the standard 8 bytes; the rest of the Code attribute layout is unchanged. This layout is intended for historical class files with version 45.0 through 45.2. This method has no enclosing class version to check, so the caller must select the layout. The selection also applies to Code attributes encountered while reading nested attributes.- Parameters:
dataInput- Input stream.constantPool- Constant pool.compactCodeHeader- Whether to read compact four-byte Code headers (true) or standard eight-byte headers (false).- Returns:
- The attribute.
- Throws:
IOException- Thrown if an I/O error occurs.ClassFormatException- Thrown if the attribute is malformed or exceeds the nesting limit.- Since:
- 6.14.0
- See Also:
-
readAttribute
public static Attribute readAttribute(DataInputStream dataInputStream, ConstantPool constantPool) throws IOException Reads one attribute using standard eight-byte Code headers.- Parameters:
dataInputStream- Input stream.constantPool- Array of constants.- Returns:
- Attribute.
- Throws:
IOException- Thrown if an I/O error occurs.- See Also:
-
removeAttributeReader
Remove attribute reader- Parameters:
name- The name of the attribute as stored in the class file.
-
accept
Called by objects that are traversing the nodes of the tree implicitly defined by the contents of a Java class. That is, the hierarchy of methods, fields, attributes, and other elements forms a tree of objects. -
clone
-
copy
Creates a deep copy of this attribute.- Parameters:
constantPool- constant pool to save.- Returns:
- deep copy of this attribute.
-
dump
Dumps attribute to file stream in binary format.- Parameters:
file- Output file stream.- Throws:
IOException- Thrown if an I/O error occurs.
-
getConstantPool
Gets the constant pool used by this object.- Returns:
- Constant pool used by this object.
- See Also:
-
getLength
Gets the length of attribute field in bytes.- Returns:
- Length of attribute field in bytes.
-
getName
-
getNameIndex
Gets the name index in constant pool of attribute name.- Returns:
- Name index in constant pool of attribute name.
-
getTag
Gets the tag of attribute, that is, its type.- Returns:
- Tag of attribute, that is, its type. Value may not be altered, thus there is no setTag() method.
-
setConstantPool
Sets the constant pool to be used for this object.- Parameters:
constantPool- Constant pool to be used for this object.- See Also:
-
setLength
Sets the length in bytes.- Parameters:
length- length in bytes.
-
setNameIndex
Sets the name index of attribute.- Parameters:
nameIndex- of attribute.
-
toString
-