You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2014/09/12 15:09:13 UTC
svn commit: r1624534 - in /tomcat/tc7.0.x/trunk: ./
java/org/apache/tomcat/util/bcel/ java/org/apache/tomcat/util/bcel/classfile/
java/org/apache/tomcat/util/bcel/util/
Author: markt
Date: Fri Sep 12 13:09:13 2014
New Revision: 1624534
URL: http://svn.apache.org/r1624534
Log:
Port more code removal from trunk
Removed:
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/FieldOrMethod.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/RuntimeInvisibleAnnotations.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/RuntimeInvisibleParameterAnnotations.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/util/
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ClassParser.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Constant.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantClass.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantDouble.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantFloat.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantInteger.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantLong.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/JavaClass.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotations.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1624162-1624165,1624220,1624233,1624235,1624246,1624252,1624254,1624396,1624408
Propchange: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/
------------------------------------------------------------------------------
Merged /tomcat/trunk/java/org/apache/tomcat/util/bcel:r1624162-1624165,1624220,1624233,1624235,1624246,1624252,1624254,1624396,1624408
Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java?rev=1624534&r1=1624533&r2=1624534&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Attribute.java Fri Sep 12 13:09:13 2014
@@ -133,14 +133,14 @@ public abstract class Attribute implemen
return new RuntimeVisibleAnnotations(name_index, length, file,
constant_pool);
case Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS:
- return new RuntimeInvisibleAnnotations(name_index, length, file,
- constant_pool);
+ Utility.swallowAnnotations(file);
+ return null;
case Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS:
return new RuntimeVisibleParameterAnnotations(name_index, length,
file, constant_pool);
case Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS:
- return new RuntimeInvisibleParameterAnnotations(name_index, length,
- file, constant_pool);
+ Utility.swallowParameterAnnotations(file);
+ return null;
case Constants.ATTR_ANNOTATION_DEFAULT:
return new AnnotationDefault(name_index, length, file,
constant_pool);
Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ClassParser.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ClassParser.java?rev=1624534&r1=1624533&r2=1624534&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ClassParser.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ClassParser.java Fri Sep 12 13:09:13 2014
@@ -53,8 +53,6 @@ public final class ClassParser {
private int access_flags; // Access rights of parsed class
private int[] interfaces; // Names of implemented interfaces
private ConstantPool constant_pool; // collection of constants
- private FieldOrMethod[] fields; // class fields, i.e., its variables
- private FieldOrMethod[] methods; // methods defined in the class
private Attribute[] attributes; // attributes defined in the class
private boolean is_zip; // Loaded from zip file
private static final int BUFSIZE = 8192;
@@ -216,11 +214,9 @@ public final class ClassParser {
* @throws ClassFormatException
*/
private void readFields() throws IOException, ClassFormatException {
- int fields_count;
- fields_count = file.readUnsignedShort();
- fields = new FieldOrMethod[fields_count];
+ int fields_count = file.readUnsignedShort();
for (int i = 0; i < fields_count; i++) {
- fields[i] = new FieldOrMethod(file, constant_pool);
+ Utility.swallowFieldOrMethod(file, constant_pool);
}
}
@@ -262,9 +258,8 @@ public final class ClassParser {
private void readMethods() throws IOException, ClassFormatException {
int methods_count;
methods_count = file.readUnsignedShort();
- methods = new FieldOrMethod[methods_count];
for (int i = 0; i < methods_count; i++) {
- methods[i] = new FieldOrMethod(file, constant_pool);
+ Utility.swallowFieldOrMethod(file, constant_pool);
}
}
Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Constant.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Constant.java?rev=1624534&r1=1624533&r2=1624534&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Constant.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Constant.java Fri Sep 12 13:09:13 2014
@@ -22,7 +22,6 @@ import java.io.IOException;
import java.io.Serializable;
import org.apache.tomcat.util.bcel.Constants;
-import org.apache.tomcat.util.bcel.util.BCELComparator;
/**
* Abstract superclass for classes to represent the different constant types
@@ -34,22 +33,7 @@ import org.apache.tomcat.util.bcel.util.
public abstract class Constant implements Serializable {
private static final long serialVersionUID = 2827409182154809454L;
- private static BCELComparator _cmp = new BCELComparator() {
- @Override
- public boolean equals( Object o1, Object o2 ) {
- Constant THIS = (Constant) o1;
- Constant THAT = (Constant) o2;
- return THIS.toString().equals(THAT.toString());
- }
-
-
- @Override
- public int hashCode( Object o ) {
- Constant THIS = (Constant) o;
- return THIS.toString().hashCode();
- }
- };
/* In fact this tag is redundant since we can distinguish different
* `Constant' objects by their type, i.e., via `instanceof'. In some
* places we will use the tag for switch()es anyway.
@@ -128,29 +112,4 @@ public abstract class Constant implement
public String toString() {
return "[" + tag + "]";
}
-
-
- /**
- * Return value as defined by given BCELComparator strategy.
- * By default two Constant objects are said to be equal when
- * the result of toString() is equal.
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals( Object obj ) {
- return _cmp.equals(this, obj);
- }
-
-
- /**
- * Return value as defined by given BCELComparator strategy.
- * By default return the hashcode of the result of toString().
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- return _cmp.hashCode(this);
- }
}
Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantClass.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantClass.java?rev=1624534&r1=1624533&r2=1624534&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantClass.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantClass.java Fri Sep 12 13:09:13 2014
@@ -43,17 +43,8 @@ public final class ConstantClass extends
* @throws IOException
*/
ConstantClass(DataInput file) throws IOException {
- this(file.readUnsignedShort());
- }
-
-
- /**
- * @param name_index Name index in constant pool. Should refer to a
- * ConstantUtf8.
- */
- public ConstantClass(int name_index) {
super(Constants.CONSTANT_Class);
- this.name_index = name_index;
+ this.name_index = file.readUnsignedShort();
}
Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantDouble.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantDouble.java?rev=1624534&r1=1624533&r2=1624534&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantDouble.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantDouble.java Fri Sep 12 13:09:13 2014
@@ -37,22 +37,14 @@ public final class ConstantDouble extend
/**
- * @param bytes Data
- */
- public ConstantDouble(double bytes) {
- super(Constants.CONSTANT_Double);
- this.bytes = bytes;
- }
-
-
- /**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantDouble(DataInput file) throws IOException {
- this(file.readDouble());
+ super(Constants.CONSTANT_Double);
+ this.bytes = file.readDouble();
}
Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantFloat.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantFloat.java?rev=1624534&r1=1624533&r2=1624534&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantFloat.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantFloat.java Fri Sep 12 13:09:13 2014
@@ -37,22 +37,14 @@ public final class ConstantFloat extends
/**
- * @param bytes Data
- */
- public ConstantFloat(float bytes) {
- super(Constants.CONSTANT_Float);
- this.bytes = bytes;
- }
-
-
- /**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantFloat(DataInput file) throws IOException {
- this(file.readFloat());
+ super(Constants.CONSTANT_Float);
+ this.bytes = file.readFloat();
}
Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantInteger.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantInteger.java?rev=1624534&r1=1624533&r2=1624534&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantInteger.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantInteger.java Fri Sep 12 13:09:13 2014
@@ -37,22 +37,14 @@ public final class ConstantInteger exten
/**
- * @param bytes Data
- */
- public ConstantInteger(int bytes) {
- super(Constants.CONSTANT_Integer);
- this.bytes = bytes;
- }
-
-
- /**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantInteger(DataInput file) throws IOException {
- this(file.readInt());
+ super(Constants.CONSTANT_Integer);
+ this.bytes = file.readInt();
}
Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantLong.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantLong.java?rev=1624534&r1=1624533&r2=1624534&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantLong.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantLong.java Fri Sep 12 13:09:13 2014
@@ -37,22 +37,14 @@ public final class ConstantLong extends
/**
- * @param bytes Data
- */
- public ConstantLong(long bytes) {
- super(Constants.CONSTANT_Long);
- this.bytes = bytes;
- }
-
-
- /**
* Initialize instance from file data.
*
* @param file Input stream
* @throws IOException
*/
ConstantLong(DataInput file) throws IOException {
- this(file.readLong());
+ super(Constants.CONSTANT_Long);
+ this.bytes = file.readLong();
}
Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java?rev=1624534&r1=1624533&r2=1624534&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java Fri Sep 12 13:09:13 2014
@@ -16,7 +16,6 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.HashMap;
@@ -73,17 +72,6 @@ public final class ConstantUtf8 extends
return getInstance(file.readUTF());
}
- /**
- * Initialize instance from file data.
- *
- * @param file Input stream
- * @throws IOException
- */
- ConstantUtf8(DataInput file) throws IOException {
- super(Constants.CONSTANT_Utf8);
- bytes = file.readUTF();
- }
-
/**
* @param bytes Data
Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/JavaClass.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/JavaClass.java?rev=1624534&r1=1624533&r2=1624534&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/JavaClass.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/JavaClass.java Fri Sep 12 13:09:13 2014
@@ -21,7 +21,6 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.tomcat.util.bcel.Constants;
-import org.apache.tomcat.util.bcel.util.BCELComparator;
/**
* Represents a Java class, i.e., the data structures, constant pool,
@@ -33,7 +32,7 @@ import org.apache.tomcat.util.bcel.util.
* @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
*/
-public class JavaClass extends AccessFlags implements Comparable<JavaClass> {
+public class JavaClass extends AccessFlags {
private static final long serialVersionUID = 7029227708237523236L;
private String class_name;
@@ -46,23 +45,6 @@ public class JavaClass extends AccessFla
// Annotations are collected from certain attributes, don't do it more than necessary!
private boolean annotationsOutOfDate = true;
- private static BCELComparator _cmp = new BCELComparator() {
-
- @Override
- public boolean equals( Object o1, Object o2 ) {
- JavaClass THIS = (JavaClass) o1;
- JavaClass THAT = (JavaClass) o2;
- return THIS.getClassName().equals(THAT.getClassName());
- }
-
-
- @Override
- public int hashCode( Object o ) {
- JavaClass THIS = (JavaClass) o;
- return THIS.getClassName().hashCode();
- }
- };
-
/**
* Constructor gets all contents as arguments.
@@ -155,39 +137,4 @@ public class JavaClass extends AccessFla
public String getSuperclassName() {
return superclass_name;
}
-
-
- /**
- * Return value as defined by given BCELComparator strategy.
- * By default two JavaClass objects are said to be equal when
- * their class names are equal.
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals( Object obj ) {
- return _cmp.equals(this, obj);
- }
-
-
- /**
- * Return the natural ordering of two JavaClasses.
- * This ordering is based on the class name
- */
- @Override
- public int compareTo(JavaClass obj) {
- return getClassName().compareTo(obj.getClassName());
- }
-
-
- /**
- * Return value as defined by given BCELComparator strategy.
- * By default return the hashcode of the class name.
- *
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- return _cmp.hashCode(this);
- }
}
Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotations.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotations.java?rev=1624534&r1=1624533&r2=1624534&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotations.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotations.java Fri Sep 12 13:09:13 2014
@@ -41,8 +41,7 @@ public abstract class ParameterAnnotatio
*/
ParameterAnnotations(int name_index, int length,
DataInputStream file, ConstantPool constant_pool) throws IOException {
- this(name_index, length, (ParameterAnnotationEntry[]) null,
- constant_pool);
+ super(name_index, length, constant_pool);
num_parameters = (file.readUnsignedByte());
parameter_annotation_table = new ParameterAnnotationEntry[num_parameters];
for (int i = 0; i < num_parameters; i++) {
@@ -52,19 +51,6 @@ public abstract class ParameterAnnotatio
/**
- * @param name_index Index pointing to the name <em>Code</em>
- * @param length Content length in bytes
- * @param parameter_annotation_table the actual parameter annotations
- * @param constant_pool Array of constants
- */
- public ParameterAnnotations(int name_index, int length,
- ParameterAnnotationEntry[] parameter_annotation_table, ConstantPool constant_pool) {
- super(name_index, length, constant_pool);
- setParameterAnnotationTable(parameter_annotation_table);
- }
-
-
- /**
* @param parameter_annotation_table the entries to set in this parameter annotation
*/
public final void setParameterAnnotationTable(
Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java?rev=1624534&r1=1624533&r2=1624534&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java Fri Sep 12 13:09:13 2014
@@ -96,14 +96,14 @@ final class Utility {
static void swallowStackMap(DataInput file) throws IOException {
int map_length = file.readUnsignedShort();
for (int i = 0; i < map_length; i++) {
- Utility.swallowStackMapEntry(file);
+ swallowStackMapEntry(file);
}
}
static void swallowStackMapTable(DataInputStream file) throws IOException {
int map_length = file.readUnsignedShort();
for (int i = 0; i < map_length; i++) {
- Utility.swallowStackMapTableEntry(file);
+ swallowStackMapTableEntry(file);
}
}
@@ -122,11 +122,11 @@ final class Utility {
file.readShort(); // Unused byte_code_offset
int number_of_locals = file.readShort();
for (int i = 0; i < number_of_locals; i++) {
- Utility.swallowStackMapType(file);
+ swallowStackMapType(file);
}
int number_of_stack_items = file.readShort();
for (int i = 0; i < number_of_stack_items; i++) {
- Utility.swallowStackMapType(file);
+ swallowStackMapType(file);
}
}
@@ -137,10 +137,10 @@ final class Utility {
// NO-OP
} else if (frame_type >= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME &&
frame_type <= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) {
- Utility.swallowStackMapType(file); // Unused single stack item
+ swallowStackMapType(file); // Unused single stack item
} else if (frame_type == Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
file.readShort(); // Unused byte_code_offset_delta
- Utility.swallowStackMapType(file); // Unused single stack item
+ swallowStackMapType(file); // Unused single stack item
} else if (frame_type >= Constants.CHOP_FRAME &&
frame_type <= Constants.CHOP_FRAME_MAX) {
file.readShort(); // Unused byte_code_offset_delta
@@ -151,17 +151,17 @@ final class Utility {
file.readShort(); // Unused byte_code_offset_delta
int number_of_locals = frame_type - 251;
for (int i = 0; i < number_of_locals; i++) {
- Utility.swallowStackMapType(file);
+ swallowStackMapType(file);
}
} else if (frame_type == Constants.FULL_FRAME) {
file.readShort(); // Unused byte_code_offset_delta
int number_of_locals = file.readShort();
for (int i = 0; i < number_of_locals; i++) {
- Utility.swallowStackMapType(file);
+ swallowStackMapType(file);
}
int number_of_stack_items = file.readShort();
for (int i = 0; i < number_of_stack_items; i++) {
- Utility.swallowStackMapType(file);
+ swallowStackMapType(file);
}
} else {
/* Can't happen */
@@ -206,14 +206,14 @@ final class Utility {
*/
int exception_table_length = file.readUnsignedShort();
for (int i = 0; i < exception_table_length; i++) {
- Utility.swallowCodeException(file);
+ swallowCodeException(file);
}
/* Read all attributes, currently `LineNumberTable' and
* `LocalVariableTable'
*/
int attributes_count = file.readUnsignedShort();
for (int i = 0; i < attributes_count; i++) {
- Attribute.readAttribute(file, constant_pool);
+ swallowAttribute(file, constant_pool);
}
}
@@ -227,28 +227,28 @@ final class Utility {
static void swallowLineNumberTable(DataInput file) throws IOException {
int line_number_table_length = (file.readUnsignedShort());
for (int i = 0; i < line_number_table_length; i++) {
- Utility.swallowLineNumber(file);
+ swallowLineNumber(file);
}
}
static void swallowLocalVariableTable(DataInput file) throws IOException {
int local_variable_table_length = (file.readUnsignedShort());
for (int i = 0; i < local_variable_table_length; i++) {
- Utility.swallowLocalVariable(file);
+ swallowLocalVariable(file);
}
}
static void swallowLocalVariableTypeTable(DataInput file) throws IOException {
int local_variable_type_table_length = (file.readUnsignedShort());
for(int i=0; i < local_variable_type_table_length; i++) {
- Utility.swallowLocalVariable(file);
+ swallowLocalVariable(file);
}
}
static void swallowInnerClasses(DataInput file) throws IOException {
int number_of_classes = file.readUnsignedShort();
for (int i = 0; i < number_of_classes; i++) {
- Utility.swallowInnerClass(file);
+ swallowInnerClass(file);
}
}
@@ -295,4 +295,178 @@ final class Utility {
file.readUnsignedShort(); // Unused bootstrap_method_attr_index
file.readUnsignedShort(); // Unused name_and_type_index
}
+
+ static void swallowAnnotations(DataInput file) throws IOException {
+ final int annotation_table_length = (file.readUnsignedShort());
+ for (int i = 0; i < annotation_table_length; i++) {
+ swallowAnnotationEntry(file);
+ }
+ }
+
+ static void swallowAnnotationEntry(DataInput file)
+ throws IOException {
+ file.readUnsignedShort(); // Unused type index
+ final int num_element_value_pairs = file.readUnsignedShort();
+ for (int i = 0; i < num_element_value_pairs; i++) {
+ file.readUnsignedShort(); // Unused name index
+ swallowElementValue(file);
+ }
+ }
+
+ static void swallowParameterAnnotations(DataInput file) throws IOException {
+ final int annotation_table_length = (file.readUnsignedByte());
+ for (int i = 0; i < annotation_table_length; i++) {
+ swallowParameterAnnotationEntry(file);
+ }
+ }
+
+ static void swallowParameterAnnotationEntry(DataInput file)
+ throws IOException {
+ final int annotation_table_length = file.readUnsignedShort();
+ for (int i = 0; i < annotation_table_length; i++) {
+ swallowAnnotationEntry(file);
+ }
+ }
+
+ static void swallowElementValue(DataInput file) throws IOException {
+
+ byte type = file.readByte();
+ switch (type) {
+ case 'B': // byte
+ case 'C': // char
+ case 'D': // double
+ case 'F': // float
+ case 'I': // int
+ case 'J': // long
+ case 'S': // short
+ case 'Z': // boolean
+ case 's': // String
+ case 'c': // Class
+ file.readUnsignedShort(); // Unused value index
+ break;
+ case 'e': // Enum constant
+ file.readUnsignedShort(); // Unused type_index
+ file.readUnsignedShort(); // Unused value index
+ break;
+ case '@': // Annotation
+ swallowAnnotationEntry(file);
+ break;
+ case '[': // Array
+ int numArrayVals = file.readUnsignedShort();
+ for (int j = 0; j < numArrayVals; j++)
+ {
+ swallowElementValue(file);
+ }
+ break;
+ default:
+ throw new ClassFormatException(
+ "Unexpected element value kind in annotation: " + type);
+ }
+ }
+
+ static void swallowFieldOrMethod(DataInputStream file, ConstantPool constant_pool)
+ throws IOException {
+ file.readUnsignedShort(); // Unused access flags
+ file.readUnsignedShort(); // name index
+ file.readUnsignedShort(); // signature index
+
+ int attributes_count = file.readUnsignedShort();
+ for (int i = 0; i < attributes_count; i++) {
+ swallowAttribute(file, constant_pool);
+ }
+ }
+
+ static void swallowAttribute(DataInputStream file, ConstantPool constant_pool)
+ throws IOException {
+ byte tag = Constants.ATTR_UNKNOWN; // Unknown attribute
+ // Get class name from constant pool via `name_index' indirection
+ int name_index = file.readUnsignedShort();
+ ConstantUtf8 c =
+ (ConstantUtf8) constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8);
+ String name = c.getBytes();
+ // Length of data in bytes
+ int length = file.readInt();
+ // Compare strings to find known attribute
+ for (byte i = 0; i < Constants.KNOWN_ATTRIBUTES; i++) {
+ if (name.equals(Constants.ATTRIBUTE_NAMES[i])) {
+ tag = i; // found!
+ break;
+ }
+ }
+ // Call proper constructor, depending on `tag'
+ switch (tag)
+ {
+ case Constants.ATTR_UNKNOWN:
+ swallowUnknownAttribute(file, length);
+ break;
+ case Constants.ATTR_CONSTANT_VALUE:
+ swallowConstantValue(file);
+ break;
+ case Constants.ATTR_SOURCE_FILE:
+ swallowSourceFile(file);
+ break;
+ case Constants.ATTR_CODE:
+ swallowCode(file, constant_pool);
+ break;
+ case Constants.ATTR_EXCEPTIONS:
+ swallowExceptionTable(file);
+ break;
+ case Constants.ATTR_LINE_NUMBER_TABLE:
+ swallowLineNumberTable(file);
+ break;
+ case Constants.ATTR_LOCAL_VARIABLE_TABLE:
+ swallowLocalVariableTable(file);
+ break;
+ case Constants.ATTR_INNER_CLASSES:
+ swallowInnerClasses(file);
+ break;
+ case Constants.ATTR_SYNTHETIC:
+ swallowSynthetic(length);
+ break;
+ case Constants.ATTR_DEPRECATED:
+ swallowDeprecated(length);
+ break;
+ case Constants.ATTR_PMG:
+ swallowPMCClass(file);
+ break;
+ case Constants.ATTR_SIGNATURE:
+ swallowSignature(file);
+ break;
+ case Constants.ATTR_STACK_MAP:
+ swallowStackMap(file);
+ break;
+ case Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS:
+ case Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS:
+ swallowAnnotations(file);
+ break;
+ case Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS:
+ case Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS:
+ swallowParameterAnnotations(file);
+ break;
+ case Constants.ATTR_ANNOTATION_DEFAULT:
+ swallowAnnotationDefault(file);
+ break;
+ case Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE:
+ swallowLocalVariableTypeTable(file);
+ break;
+ case Constants.ATTR_ENCLOSING_METHOD:
+ swallowEnclosingMethod(file);
+ break;
+ case Constants.ATTR_STACK_MAP_TABLE:
+ swallowStackMapTable(file);
+ break;
+ case Constants.ATTR_BOOTSTRAP_METHODS:
+ swallowBootstrapMethods(file);
+ break;
+ case Constants.ATTR_METHOD_PARAMETERS:
+ swallowMethodParameters(file);
+ break;
+ default: // Never reached
+ throw new ClassFormatException("Unrecognized attribute type tag parsed: " + tag);
+ }
+ }
+
+ static void swallowAnnotationDefault(DataInput file) throws IOException {
+ swallowElementValue(file);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org