--- old/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Attribute.java 2020-01-16 18:00:17.366750171 +0000
+++ new/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/classfile/Attribute.java 2020-01-16 18:00:16.872737942 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -36,7 +36,6 @@
* Synthetic attributes are supported. The Unknown
* attribute stands for non-standard-attributes.
*
- * @version $Id$
* @see ConstantValue
* @see SourceFile
* @see Code
@@ -48,44 +47,15 @@
* @see Synthetic
* @see Deprecated
* @see Signature
- * @LastModified: Jun 2019
+ * @LastModified: Jan 2020
*/
public abstract class Attribute implements Cloneable, Node {
-
+ private static final boolean debug = false;
private int name_index; // Points to attribute name in constant pool
private int length; // Content length of attribute field
private final byte tag; // Tag to distinguish subclasses
private ConstantPool constant_pool;
- protected Attribute(final byte tag, final int name_index, final int length, final ConstantPool constant_pool) {
- this.tag = tag;
- this.name_index = name_index;
- this.length = length;
- this.constant_pool = constant_pool;
- }
-
- /**
- * Called by objects that are traversing the nodes of the tree implicitely
- * defined by the contents of a Java class. I.e., the hierarchy of methods,
- * fields, attributes, etc. spawns a tree of objects.
- *
- * @param v Visitor object
- */
- @Override
- public abstract void accept(Visitor v);
-
- /**
- * Dump attribute to file stream in binary format.
- *
- * @param file Output file stream
- * @throws IOException
- */
- public void dump(final DataOutputStream file) throws IOException
- {
- file.writeShort(name_index);
- file.writeInt(length);
- }
-
private static final Map readers = new HashMap<>();
/**
@@ -101,34 +71,10 @@
readers.put(name, r);
}
- /**
- * Remove attribute reader
- *
- * @param name the name of the attribute as stored in the class file
- */
- public static void removeAttributeReader(final String name)
- {
- readers.remove(name);
- }
-
- /**
- * Class method reads one attribute from the input data stream. This method
- * must not be accessible from the outside. It is called by the Field and
- * Method constructor methods.
- *
- * @see Field
- * @see Method
- *
- * @param file Input stream
- * @param constant_pool Array of constants
- * @return Attribute
- * @throws IOException
- * @throws ClassFormatException
- */
- public static Attribute readAttribute(final DataInputStream file, final ConstantPool constant_pool)
- throws IOException, ClassFormatException
- {
- return readAttribute((DataInput) file, constant_pool);
+ protected static void println(final String msg) {
+ if (debug) {
+ System.err.println(msg);
+ }
}
/**
@@ -203,7 +149,7 @@
case Const.ATTR_STACK_MAP:
// old style stack map: unneeded for JDK5 and below;
// illegal(?) for JDK6 and above. So just delete with a warning.
- System.err.println("Warning: Obsolete StackMap attribute ignored.");
+ println("Warning: Obsolete StackMap attribute ignored.");
return new Unknown(name_index, length, file, constant_pool);
case Const.ATTR_RUNTIME_VISIBLE_ANNOTATIONS:
return new RuntimeVisibleAnnotations(name_index, length, file, constant_pool);
@@ -227,6 +173,16 @@
return new BootstrapMethods(name_index, length, file, constant_pool);
case Const.ATTR_METHOD_PARAMETERS:
return new MethodParameters(name_index, length, file, constant_pool);
+ case Const.ATTR_MODULE:
+ return new Module(name_index, length, file, constant_pool);
+ case Const.ATTR_MODULE_PACKAGES:
+ return new ModulePackages(name_index, length, file, constant_pool);
+ case Const.ATTR_MODULE_MAIN_CLASS:
+ return new ModuleMainClass(name_index, length, file, constant_pool);
+ case Const.ATTR_NEST_HOST:
+ return new NestHost(name_index, length, file, constant_pool);
+ case Const.ATTR_NEST_MEMBERS:
+ return new NestMembers(name_index, length, file, constant_pool);
default:
// Never reached
throw new IllegalStateException("Unrecognized attribute type tag parsed: " + tag);
@@ -234,53 +190,91 @@
}
/**
- * @return Name of attribute
- * @since 6.0
+ * Class method reads one attribute from the input data stream. This method
+ * must not be accessible from the outside. It is called by the Field and
+ * Method constructor methods.
+ *
+ * @see Field
+ * @see Method
+ *
+ * @param file Input stream
+ * @param constant_pool Array of constants
+ * @return Attribute
+ * @throws IOException
+ * @throws ClassFormatException
*/
- public String getName()
+ public static Attribute readAttribute(final DataInputStream file, final ConstantPool constant_pool)
+ throws IOException, ClassFormatException
{
- final ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(name_index, Const.CONSTANT_Utf8);
- return c.getBytes();
+ return readAttribute((DataInput) file, constant_pool);
}
/**
- * @return Length of attribute field in bytes.
+ * Remove attribute reader
+ *
+ * @param name the name of the attribute as stored in the class file
*/
- public final int getLength()
+ public static void removeAttributeReader(final String name)
{
- return length;
+ readers.remove(name);
}
- /**
- * @param length length in bytes.
- */
- public final void setLength(final int length)
+ protected Attribute(final byte tag, final int name_index, final int length, final ConstantPool constant_pool)
{
+ this.tag = tag;
+ this.name_index = name_index;
this.length = length;
+ this.constant_pool = constant_pool;
}
/**
- * @param name_index of attribute.
+ * Called by objects that are traversing the nodes of the tree implicitely
+ * defined by the contents of a Java class. I.e., the hierarchy of methods,
+ * fields, attributes, etc. spawns a tree of objects.
+ *
+ * @param v
+ * Visitor object
*/
- public final void setNameIndex(final int name_index)
- {
- this.name_index = name_index;
- }
+ @Override
+ public abstract void accept(Visitor v);
/**
- * @return Name index in constant pool of attribute name.
+ * Use copy() if you want to have a deep copy(), i.e., with all references
+ * copied correctly.
+ *
+ * @return shallow copy of this attribute
*/
- public final int getNameIndex()
+ @Override
+ public Object clone()
{
- return name_index;
+ Attribute attr = null;
+ try
+ {
+ attr = (Attribute) super.clone();
+ }
+ catch (final CloneNotSupportedException e)
+ {
+ throw new Error("Clone Not Supported"); // never happens
+ }
+ return attr;
}
/**
- * @return Tag of attribute, i.e., its type. Value may not be altered, thus there is no setTag() method.
+ * @return deep copy of this attribute
*/
- public final byte getTag()
+ public abstract Attribute copy(ConstantPool _constant_pool);
+
+ /**
+ * Dump attribute to file stream in binary format.
+ *
+ * @param file
+ * Output file stream
+ * @throws IOException
+ */
+ public void dump(final DataOutputStream file) throws IOException
{
- return tag;
+ file.writeShort(name_index);
+ file.writeInt(length);
}
/**
@@ -293,6 +287,40 @@
}
/**
+ * @return Length of attribute field in bytes.
+ */
+ public final int getLength()
+ {
+ return length;
+ }
+
+ /**
+ * @return Name of attribute
+ * @since 6.0
+ */
+ public String getName()
+ {
+ final ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(name_index, Const.CONSTANT_Utf8);
+ return c.getBytes();
+ }
+
+ /**
+ * @return Name index in constant pool of attribute name.
+ */
+ public final int getNameIndex()
+ {
+ return name_index;
+ }
+
+ /**
+ * @return Tag of attribute, i.e., its type. Value may not be altered, thus there is no setTag() method.
+ */
+ public final byte getTag()
+ {
+ return tag;
+ }
+
+ /**
* @param constant_pool Constant pool to be used for this object.
* @see ConstantPool
*/
@@ -302,30 +330,20 @@
}
/**
- * Use copy() if you want to have a deep copy(), i.e., with all references
- * copied correctly.
- *
- * @return shallow copy of this attribute
+ * @param length length in bytes.
*/
- @Override
- public Object clone()
+ public final void setLength(final int length)
{
- Attribute attr = null;
- try
- {
- attr = (Attribute) super.clone();
- }
- catch (final CloneNotSupportedException e)
- {
- throw new Error("Clone Not Supported"); // never happens
- }
- return attr;
+ this.length = length;
}
/**
- * @return deep copy of this attribute
+ * @param name_index of attribute.
*/
- public abstract Attribute copy(ConstantPool _constant_pool);
+ public final void setNameIndex(final int name_index)
+ {
+ this.name_index = name_index;
+ }
/**
* @return attribute name.