This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
The following commit(s) were added to refs/heads/master by this push:
new 4d89da4 [BCEL-316] org.apache.bcel.classfile.Attribute class and
subclasses should NOT log to the console by default
4d89da4 is described below
commit 4d89da4f52f6ae26a4917ba79259e8c89c67eb77
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Apr 12 09:05:05 2019 -0400
[BCEL-316] org.apache.bcel.classfile.Attribute class and subclasses
should NOT log to the console by default
---
src/changes/changes.xml | 4 +
.../java/org/apache/bcel/classfile/Attribute.java | 256 +++++++++++----------
.../java/org/apache/bcel/classfile/Deprecated.java | 2 +-
.../java/org/apache/bcel/classfile/PMGClass.java | 2 +-
.../java/org/apache/bcel/classfile/Synthetic.java | 2 +-
.../bcel/verifier/structurals/Subroutines.java | 2 +-
6 files changed, 140 insertions(+), 128 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 97beddc..90b1563 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -62,6 +62,10 @@ The <action> type attribute can be add,update,fix,remove.
-->
<body>
+ <release version="6.3.2" date="2019-MM-DD" description="Bug fix release">
+ <action issue="BCEL-316" type="fix" dev="ggregory" due-to="Gary
Gregory">org.apache.bcel.classfile.Attribute class and subclasses should NOT
log to the console by default.</action>
+ </release>
+
<release version="6.3.1" date="2019-03-20" description="Bug fix release">
<action issue="BCEL-267" type="fix" dev="ggregory" due-to="Stephan
Herrmann, Sebb, Gary Gregory, Torsten Curdt">Race conditions on static fields
in BranchHandle and InstructionHandle.</action>
<action issue="BCEL-297" type="fix" dev="ggregory" due-to="Mark Roberts,
mingleizhang">Possible NPE in override implementation of Object.equals
(#20)</action>
diff --git a/src/main/java/org/apache/bcel/classfile/Attribute.java
b/src/main/java/org/apache/bcel/classfile/Attribute.java
index 9b5e2a6..3fda725 100644
--- a/src/main/java/org/apache/bcel/classfile/Attribute.java
+++ b/src/main/java/org/apache/bcel/classfile/Attribute.java
@@ -49,62 +49,8 @@ import org.apache.bcel.Const;
*/
public abstract class Attribute implements Cloneable, Node {
- /**
- * @deprecated (since 6.0) will be made private; do not access directly,
use getter/setter
- */
- @java.lang.Deprecated
- protected int name_index; // Points to attribute name in constant pool
TODO make private (has getter & setter)
-
- /**
- * @deprecated (since 6.0) (since 6.0) will be made private; do not access
directly, use getter/setter
- */
- @java.lang.Deprecated
- protected int length; // Content length of attribute field TODO make
private (has getter & setter)
-
- /**
- * @deprecated (since 6.0) will be made private; do not access directly,
use getter/setter
- */
- @java.lang.Deprecated
- protected byte tag; // Tag to distinguish subclasses TODO make private &
final; supposed to be immutable
-
- /**
- * @deprecated (since 6.0) will be made private; do not access directly,
use getter/setter
- */
- @java.lang.Deprecated
- protected ConstantPool constant_pool; // TODO make private (has getter &
setter)
-
- 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 boolean debug =
Boolean.getBoolean(Attribute.class.getCanonicalName() + ".debug"); // Debugging
on/off
+
private static final Map<String, Object> readers = new HashMap<>();
/**
@@ -135,34 +81,10 @@ public abstract class Attribute implements Cloneable, Node
{
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);
+ }
}
/**
@@ -237,7 +159,7 @@ public abstract class Attribute implements Cloneable, Node {
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);
@@ -268,53 +190,115 @@ public abstract class Attribute implements Cloneable,
Node {
}
/**
- * @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.
+ * @deprecated (since 6.0) will be made private; do not access directly,
use getter/setter
*/
- public final void setLength(final int length)
- {
- this.length = length;
- }
+ @java.lang.Deprecated
+ protected int name_index; // Points to attribute name in constant pool
TODO make private (has getter & setter)
/**
- * @param name_index of attribute.
+ * @deprecated (since 6.0) (since 6.0) will be made private; do not access
directly, use getter/setter
*/
- public final void setNameIndex(final int name_index)
+ @java.lang.Deprecated
+ protected int length; // Content length of attribute field TODO make
private (has getter & setter)
+
+ /**
+ * @deprecated (since 6.0) will be made private; do not access directly,
use getter/setter
+ */
+ @java.lang.Deprecated
+ protected byte tag; // Tag to distinguish subclasses TODO make private &
final; supposed to be immutable
+
+ /**
+ * @deprecated (since 6.0) will be made private; do not access directly,
use getter/setter
+ */
+ @java.lang.Deprecated
+ protected ConstantPool constant_pool; // TODO make private (has getter &
setter)
+
+ 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;
}
/**
- * @return Name index in constant pool of attribute name.
+ * 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 int getNameIndex()
+ @Override
+ public abstract void accept(Visitor v);
+
+ /**
+ * Use copy() if you want to have a deep copy(), i.e., with all references
+ * copied correctly.
+ *
+ * @return shallow copy of this attribute
+ */
+ @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);
}
/**
@@ -327,6 +311,40 @@ public abstract class Attribute implements Cloneable, Node
{
}
/**
+ * @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
*/
@@ -336,30 +354,20 @@ public abstract class Attribute implements Cloneable,
Node {
}
/**
- * 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.
diff --git a/src/main/java/org/apache/bcel/classfile/Deprecated.java
b/src/main/java/org/apache/bcel/classfile/Deprecated.java
index fcde152..6708e32 100644
--- a/src/main/java/org/apache/bcel/classfile/Deprecated.java
+++ b/src/main/java/org/apache/bcel/classfile/Deprecated.java
@@ -72,7 +72,7 @@ public final class Deprecated extends Attribute {
if (length > 0) {
bytes = new byte[length];
input.readFully(bytes);
- System.err.println("Deprecated attribute with length > 0");
+ println("Deprecated attribute with length > 0");
}
}
diff --git a/src/main/java/org/apache/bcel/classfile/PMGClass.java
b/src/main/java/org/apache/bcel/classfile/PMGClass.java
index e6c0806..ee74e0e 100644
--- a/src/main/java/org/apache/bcel/classfile/PMGClass.java
+++ b/src/main/java/org/apache/bcel/classfile/PMGClass.java
@@ -84,7 +84,7 @@ public final class PMGClass extends Attribute {
*/
@Override
public void accept( final Visitor v ) {
- System.err.println("Visiting non-standard PMGClass object");
+ println("Visiting non-standard PMGClass object");
}
diff --git a/src/main/java/org/apache/bcel/classfile/Synthetic.java
b/src/main/java/org/apache/bcel/classfile/Synthetic.java
index 41ad73d..9d7bf0d 100644
--- a/src/main/java/org/apache/bcel/classfile/Synthetic.java
+++ b/src/main/java/org/apache/bcel/classfile/Synthetic.java
@@ -78,7 +78,7 @@ public final class Synthetic extends Attribute {
if (length > 0) {
bytes = new byte[length];
input.readFully(bytes);
- System.err.println("Synthetic attribute with length > 0");
+ println("Synthetic attribute with length > 0");
}
}
diff --git
a/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
b/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
index 4b075a0..ddd4bee 100644
--- a/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
+++ b/src/main/java/org/apache/bcel/verifier/structurals/Subroutines.java
@@ -596,7 +596,7 @@ public class Subroutines{
return s;
}
}
-System.err.println("DEBUG: Please verify '"+any.toString(true)+"' lies in dead
code.");
+ System.err.println("DEBUG: Please verify '"+any.toString(true)+"' lies
in dead code.");
return null;
//throw new AssertionViolatedException("No subroutine for
InstructionHandle found (DEAD CODE?).");
}