Skip to content

Commit

Permalink
Merge BCEL changes from r1614166 to r1682271
Browse files Browse the repository at this point in the history
The changes consist of:
- code clean-up
- Javadoc tweaks
- some renaming
There are no functional changes

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1682311 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed May 28, 2015
1 parent db9e6c0 commit a341250
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 139 deletions.
7 changes: 5 additions & 2 deletions java/org/apache/tomcat/util/bcel/Constants.java
Expand Up @@ -24,7 +24,11 @@
*/
public interface Constants {

/** One of the access flags for fields, methods, or classes.
/**
* One of the access flags for fields, methods, or classes.
* @see "<a href='http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.5'>Flag definitions for Fields in the Java Virtual Machine Specification (Java SE 8 Edition).</a>"
* @see "<a href='http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.6'>Flag definitions for Methods in the Java Virtual Machine Specification (Java SE 8 Edition).</a>"
* @see "<a href='http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.6-300-D.1-D.1'>Flag definitions for Classes in the Java Virtual Machine Specification (Java SE 8 Edition).</a>"
*/
public static final short ACC_FINAL = 0x0010;

Expand Down Expand Up @@ -90,5 +94,4 @@ public interface Constants {
"CONSTANT_Methodref", "CONSTANT_InterfaceMethodref",
"CONSTANT_NameAndType", "", "", "CONSTANT_MethodHandle",
"CONSTANT_MethodType", "", "CONSTANT_InvokeDynamic" };

}
10 changes: 5 additions & 5 deletions java/org/apache/tomcat/util/bcel/classfile/AnnotationEntry.java
Expand Up @@ -40,20 +40,20 @@ public class AnnotationEntry implements Constants {
/**
* Creates an AnnotationEntry from a DataInputStream
*
* @param file
* @param input
* @param constant_pool
* @throws IOException
*/
AnnotationEntry(DataInput file, ConstantPool constant_pool) throws IOException {
AnnotationEntry(DataInput input, ConstantPool constant_pool) throws IOException {

this.constant_pool = constant_pool;

type_index = file.readUnsignedShort();
int num_element_value_pairs = file.readUnsignedShort();
type_index = input.readUnsignedShort();
int num_element_value_pairs = input.readUnsignedShort();

element_value_pairs = new ArrayList<>(num_element_value_pairs);
for (int i = 0; i < num_element_value_pairs; i++) {
element_value_pairs.add(new ElementValuePair(file, constant_pool));
element_value_pairs.add(new ElementValuePair(input, constant_pool));
}
}

Expand Down
9 changes: 4 additions & 5 deletions java/org/apache/tomcat/util/bcel/classfile/Annotations.java
Expand Up @@ -31,15 +31,14 @@ public class Annotations {
private final AnnotationEntry[] annotation_table;

/**
* @param file Input stream
* @param input Input stream
* @param constant_pool Array of constants
*/
Annotations(DataInput file, ConstantPool constant_pool)
throws IOException {
final int annotation_table_length = (file.readUnsignedShort());
Annotations(DataInput input, ConstantPool constant_pool) throws IOException {
final int annotation_table_length = (input.readUnsignedShort());
annotation_table = new AnnotationEntry[annotation_table_length];
for (int i = 0; i < annotation_table_length; i++) {
annotation_table[i] = new AnnotationEntry(file, constant_pool);
annotation_table[i] = new AnnotationEntry(input, constant_pool);
}
}

Expand Down
47 changes: 22 additions & 25 deletions java/org/apache/tomcat/util/bcel/classfile/ClassParser.java
Expand Up @@ -33,7 +33,7 @@
* the caller.
*
* The structure and the names comply, except for a few conveniences,
* exactly with the <A href="ftp://java.sun.com/docs/specs/vmspec.ps">
* exactly with the <A href="http://docs.oracle.com/javase/specs/">
* JVM specification 1.0</a>. See this paper for
* further details about the structure of a bytecode file.
*
Expand All @@ -43,7 +43,7 @@ public final class ClassParser {

private static final int MAGIC = 0xCAFEBABE;

private final DataInput file;
private final DataInput dataInputStream;
private String class_name, superclass_name;
private int access_flags; // Access rights of parsed class
private String[] interface_names; // Names of implemented interfaces
Expand All @@ -56,10 +56,10 @@ public final class ClassParser {
/**
* Parse class from the given stream.
*
* @param file Input stream
* @param inputStream Input stream
*/
public ClassParser(InputStream file) {
this.file = new DataInputStream(new BufferedInputStream(file, BUFSIZE));
public ClassParser(InputStream inputStream) {
this.dataInputStream = new DataInputStream(new BufferedInputStream(inputStream, BUFSIZE));
}


Expand Down Expand Up @@ -108,30 +108,29 @@ public JavaClass parse() throws IOException, ClassFormatException {
* @throws ClassFormatException
*/
private void readAttributes() throws IOException, ClassFormatException {
int attributes_count;
attributes_count = file.readUnsignedShort();
int attributes_count = dataInputStream.readUnsignedShort();
for (int i = 0; i < attributes_count; i++) {
ConstantUtf8 c;
String name;
int name_index;
int length;
// Get class name from constant pool via `name_index' indirection
name_index = file.readUnsignedShort();
name_index = dataInputStream.readUnsignedShort();
c = (ConstantUtf8) constant_pool.getConstant(name_index,
Constants.CONSTANT_Utf8);
name = c.getBytes();
// Length of data in bytes
length = file.readInt();
length = dataInputStream.readInt();

if (name.equals("RuntimeVisibleAnnotations")) {
if (runtimeVisibleAnnotations != null) {
throw new ClassFormatException(
"RuntimeVisibleAnnotations attribute is not allowed more than once in a class file");
}
runtimeVisibleAnnotations = new Annotations(file, constant_pool);
runtimeVisibleAnnotations = new Annotations(dataInputStream, constant_pool);
} else {
// All other attributes are skipped
Utility.skipFully(file, length);
Utility.skipFully(dataInputStream, length);
}
}
}
Expand All @@ -143,7 +142,7 @@ private void readAttributes() throws IOException, ClassFormatException {
* @throws ClassFormatException
*/
private void readClassInfo() throws IOException, ClassFormatException {
access_flags = file.readUnsignedShort();
access_flags = dataInputStream.readUnsignedShort();
/* Interfaces are implicitely abstract, the flag should be set
* according to the JVM specification.
*/
Expand All @@ -155,10 +154,10 @@ private void readClassInfo() throws IOException, ClassFormatException {
throw new ClassFormatException("Class can't be both final and abstract");
}

int class_name_index = file.readUnsignedShort();
int class_name_index = dataInputStream.readUnsignedShort();
class_name = Utility.getClassName(constant_pool, class_name_index);

int superclass_name_index = file.readUnsignedShort();
int superclass_name_index = dataInputStream.readUnsignedShort();
if (superclass_name_index > 0) {
// May be zero -> class is java.lang.Object
superclass_name = Utility.getClassName(constant_pool, superclass_name_index);
Expand All @@ -174,7 +173,7 @@ private void readClassInfo() throws IOException, ClassFormatException {
* @throws ClassFormatException
*/
private void readConstantPool() throws IOException, ClassFormatException {
constant_pool = new ConstantPool(file);
constant_pool = new ConstantPool(dataInputStream);
}


Expand All @@ -184,9 +183,9 @@ private void readConstantPool() throws IOException, ClassFormatException {
* @throws ClassFormatException
*/
private void readFields() throws IOException, ClassFormatException {
int fields_count = file.readUnsignedShort();
int fields_count = dataInputStream.readUnsignedShort();
for (int i = 0; i < fields_count; i++) {
Utility.swallowFieldOrMethod(file);
Utility.swallowFieldOrMethod(dataInputStream);
}
}

Expand All @@ -199,7 +198,7 @@ private void readFields() throws IOException, ClassFormatException {
* @throws ClassFormatException
*/
private void readID() throws IOException, ClassFormatException {
if (file.readInt() != MAGIC) {
if (dataInputStream.readInt() != MAGIC) {
throw new ClassFormatException("It is not a Java .class file");
}
}
Expand All @@ -211,12 +210,11 @@ private void readID() throws IOException, ClassFormatException {
* @throws ClassFormatException
*/
private void readInterfaces() throws IOException, ClassFormatException {
int interfaces_count;
interfaces_count = file.readUnsignedShort();
int interfaces_count = dataInputStream.readUnsignedShort();
if (interfaces_count > 0) {
interface_names = new String[interfaces_count];
for (int i = 0; i < interfaces_count; i++) {
int index = file.readUnsignedShort();
int index = dataInputStream.readUnsignedShort();
interface_names[i] = Utility.getClassName(constant_pool, index);
}
} else {
Expand All @@ -231,10 +229,9 @@ private void readInterfaces() throws IOException, ClassFormatException {
* @throws ClassFormatException
*/
private void readMethods() throws IOException, ClassFormatException {
int methods_count;
methods_count = file.readUnsignedShort();
int methods_count = dataInputStream.readUnsignedShort();
for (int i = 0; i < methods_count; i++) {
Utility.swallowFieldOrMethod(file);
Utility.swallowFieldOrMethod(dataInputStream);
}
}

Expand All @@ -247,6 +244,6 @@ private void readMethods() throws IOException, ClassFormatException {
private void readVersion() throws IOException, ClassFormatException {
// file.readUnsignedShort(); // Unused minor
// file.readUnsignedShort(); // Unused major
Utility.skipFully(file, 4);
Utility.skipFully(dataInputStream, 4);
}
}
22 changes: 11 additions & 11 deletions java/org/apache/tomcat/util/bcel/classfile/Constant.java
Expand Up @@ -57,28 +57,28 @@ public final byte getTag() {


/**
* Read one constant from the given file, the type depends on a tag byte.
* Read one constant from the given input, the type depends on a tag byte.
*
* @param file Input stream
* @param input Input stream
* @return Constant object
*/
static Constant readConstant(DataInput file ) throws IOException,
static Constant readConstant(DataInput input) throws IOException,
ClassFormatException {
byte b = file.readByte(); // Read tag byte
byte b = input.readByte(); // Read tag byte
int skipSize;
switch (b) {
case Constants.CONSTANT_Class:
return new ConstantClass(file);
return new ConstantClass(input);
case Constants.CONSTANT_Integer:
return new ConstantInteger(file);
return new ConstantInteger(input);
case Constants.CONSTANT_Float:
return new ConstantFloat(file);
return new ConstantFloat(input);
case Constants.CONSTANT_Long:
return new ConstantLong(file);
return new ConstantLong(input);
case Constants.CONSTANT_Double:
return new ConstantDouble(file);
return new ConstantDouble(input);
case Constants.CONSTANT_Utf8:
return ConstantUtf8.getInstance(file);
return ConstantUtf8.getInstance(input);
case Constants.CONSTANT_String:
case Constants.CONSTANT_MethodType:
skipSize = 2; // unsigned short
Expand All @@ -96,7 +96,7 @@ static Constant readConstant(DataInput file ) throws IOException,
default:
throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
}
Utility.skipFully(file, skipSize);
Utility.skipFully(input, skipSize);
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions java/org/apache/tomcat/util/bcel/classfile/ConstantLong.java
Expand Up @@ -41,9 +41,9 @@ public final class ConstantLong extends Constant {
* @param file Input stream
* @throws IOException
*/
ConstantLong(DataInput file) throws IOException {
ConstantLong(DataInput input) throws IOException {
super(Constants.CONSTANT_Long);
this.bytes = file.readLong();
this.bytes = input.readLong();
}


Expand Down
10 changes: 5 additions & 5 deletions java/org/apache/tomcat/util/bcel/classfile/ConstantPool.java
Expand Up @@ -39,20 +39,20 @@ public class ConstantPool {


/**
* Read constants from given file stream.
* Read constants from given input stream.
*
* @param file Input stream
* @param input Input stream
* @throws IOException
* @throws ClassFormatException
*/
ConstantPool(DataInput file) throws IOException, ClassFormatException {
int constant_pool_count = file.readUnsignedShort();
ConstantPool(DataInput input) throws IOException, ClassFormatException {
int constant_pool_count = input.readUnsignedShort();
constant_pool = new Constant[constant_pool_count];
/* constant_pool[0] is unused by the compiler and may be used freely
* by the implementation.
*/
for (int i = 1; i < constant_pool_count; i++) {
constant_pool[i] = Constant.readConstant(file);
constant_pool[i] = Constant.readConstant(input);
/* Quote from the JVM specification:
* "All eight byte constants take up two spots in the constant pool.
* If this is the n'th byte in the constant pool, then the next item
Expand Down
4 changes: 2 additions & 2 deletions java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java
Expand Up @@ -34,8 +34,8 @@ public final class ConstantUtf8 extends Constant {
private final String bytes;


static ConstantUtf8 getInstance(DataInput file) throws IOException {
return new ConstantUtf8(file.readUTF());
static ConstantUtf8 getInstance(DataInput input) throws IOException {
return new ConstantUtf8(input.readUTF());
}


Expand Down

0 comments on commit a341250

Please sign in to comment.