Author: markt
Date: Fri Sep 12 13:12:21 2014
New Revision: 1624535
URL: http://svn.apache.org/r1624535
Log:
Port more code removal from trunk
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/ConstantUtf8.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/classfile/Utility.java
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1624422,1624476,1624486-1624487,1624497-1624498
Propchange: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/bcel/
------------------------------------------------------------------------------
Merged
/tomcat/trunk/java/org/apache/tomcat/util/bcel:r1624422,1624476,1624486-1624487,1624497-1624498
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=1624535&r1=1624534&r2=1624535&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:12:21 2014
@@ -90,77 +90,18 @@ public abstract class Attribute implemen
// Call proper constructor, depending on `tag'
switch (tag)
{
- case Constants.ATTR_UNKNOWN:
- Utility.swallowUnknownAttribute(file, length);
- return null;
- case Constants.ATTR_CONSTANT_VALUE:
- Utility.swallowConstantValue(file);
- return null;
- case Constants.ATTR_SOURCE_FILE:
- Utility.swallowSourceFile(file);
- return null;
- case Constants.ATTR_CODE:
- Utility.swallowCode(file, constant_pool);
- return null;
- case Constants.ATTR_EXCEPTIONS:
- Utility.swallowExceptionTable(file);
- return null;
- case Constants.ATTR_LINE_NUMBER_TABLE:
- Utility.swallowLineNumberTable(file);
- return null;
- case Constants.ATTR_LOCAL_VARIABLE_TABLE:
- Utility.swallowLocalVariableTable(file);
- return null;
- case Constants.ATTR_INNER_CLASSES:
- Utility.swallowInnerClasses(file);
- return null;
- case Constants.ATTR_SYNTHETIC:
- Utility.swallowSynthetic(length);
- return null;
- case Constants.ATTR_DEPRECATED:
- Utility.swallowDeprecated(length);
- return null;
- case Constants.ATTR_PMG:
- Utility.swallowPMCClass(file);
- return null;
- case Constants.ATTR_SIGNATURE:
- Utility.swallowSignature(file);
- return null;
- case Constants.ATTR_STACK_MAP:
- Utility.swallowStackMap(file);
- return null;
case Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS:
return new RuntimeVisibleAnnotations(name_index, length, file,
constant_pool);
- case Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS:
- 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:
- Utility.swallowParameterAnnotations(file);
- return null;
case Constants.ATTR_ANNOTATION_DEFAULT:
return new AnnotationDefault(name_index, length, file,
constant_pool);
- case Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE:
- Utility.swallowLocalVariableTypeTable(file);
- return null;
- case Constants.ATTR_ENCLOSING_METHOD:
- Utility.swallowEnclosingMethod(file);
- return null;
- case Constants.ATTR_STACK_MAP_TABLE:
- Utility.swallowStackMapTable(file);
- return null;
- case Constants.ATTR_BOOTSTRAP_METHODS:
- Utility.swallowBootstrapMethods(file);
- return null;
- case Constants.ATTR_METHOD_PARAMETERS:
- Utility.swallowMethodParameters(file);
+ default: // All other attributes are skipped
+ Utility.skipFully(file, length);
return null;
- default: // Never reached
- throw new IllegalStateException("Unrecognized attribute type tag
parsed: " + tag);
}
}
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=1624535&r1=1624534&r2=1624535&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:12:21 2014
@@ -216,7 +216,7 @@ public final class ClassParser {
private void readFields() throws IOException, ClassFormatException {
int fields_count = file.readUnsignedShort();
for (int i = 0; i < fields_count; i++) {
- Utility.swallowFieldOrMethod(file, constant_pool);
+ Utility.swallowFieldOrMethod(file);
}
}
@@ -259,7 +259,7 @@ public final class ClassParser {
int methods_count;
methods_count = file.readUnsignedShort();
for (int i = 0; i < methods_count; i++) {
- Utility.swallowFieldOrMethod(file, constant_pool);
+ Utility.swallowFieldOrMethod(file);
}
}
@@ -270,7 +270,8 @@ public final class ClassParser {
* @throws ClassFormatException
*/
private void readVersion() throws IOException, ClassFormatException {
- file.readUnsignedShort(); // Unused minor
- file.readUnsignedShort(); // Unused major
+ // file.readUnsignedShort(); // Unused minor
+ // file.readUnsignedShort(); // Unused major
+ Utility.skipFully(file, 4);
}
}
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=1624535&r1=1624534&r2=1624535&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:12:21 2014
@@ -68,17 +68,10 @@ public abstract class Constant implement
static Constant readConstant( DataInputStream file ) throws IOException,
ClassFormatException {
byte b = file.readByte(); // Read tag byte
+ int skipSize;
switch (b) {
case Constants.CONSTANT_Class:
return new ConstantClass(file);
- case Constants.CONSTANT_Fieldref:
- case Constants.CONSTANT_Methodref:
- case Constants.CONSTANT_InterfaceMethodref:
- Utility.swallowConstantCP(file);
- return null;
- case Constants.CONSTANT_String:
- Utility.swallowConstantString(file);
- return null;
case Constants.CONSTANT_Integer:
return new ConstantInteger(file);
case Constants.CONSTANT_Float:
@@ -87,23 +80,27 @@ public abstract class Constant implement
return new ConstantLong(file);
case Constants.CONSTANT_Double:
return new ConstantDouble(file);
- case Constants.CONSTANT_NameAndType:
- Utility.swallowConstantNameAndType(file);
- return null;
case Constants.CONSTANT_Utf8:
return ConstantUtf8.getInstance(file);
- case Constants.CONSTANT_MethodHandle:
- Utility.swallowConstantMethodHandle(file);
- return null;
+ case Constants.CONSTANT_String:
case Constants.CONSTANT_MethodType:
- Utility.swallowConstantMethodType(file);
- return null;
+ skipSize = 2; // unsigned short
+ break;
+ case Constants.CONSTANT_MethodHandle:
+ skipSize = 3; // unsigned byte, unsigned short
+ break;
+ case Constants.CONSTANT_Fieldref:
+ case Constants.CONSTANT_Methodref:
+ case Constants.CONSTANT_InterfaceMethodref:
+ case Constants.CONSTANT_NameAndType:
case Constants.CONSTANT_InvokeDynamic:
- Utility.swallowConstantInvokeDynamic(file);
- return null;
+ skipSize = 4; // unsigned short, unsigned short
+ break;
default:
throw new ClassFormatException("Invalid byte tag in constant
pool: " + b);
}
+ Utility.skipFully(file, skipSize);
+ return null;
}
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=1624535&r1=1624534&r2=1624535&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:12:21 2014
@@ -18,9 +18,6 @@ package org.apache.tomcat.util.bcel.clas
import java.io.DataInputStream;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
import org.apache.tomcat.util.bcel.Constants;
@@ -37,39 +34,9 @@ public final class ConstantUtf8 extends
private static final long serialVersionUID = 8119001312020421976L;
private final String bytes;
- private static final int MAX_CACHE_ENTRIES = 20000;
- private static final int INITIAL_CACHE_CAPACITY =
(int)(MAX_CACHE_ENTRIES/0.75);
- private static HashMap<String, ConstantUtf8> cache;
-
- private static synchronized ConstantUtf8 getCachedInstance(String s) {
- if (s.length() > 200) {
- return new ConstantUtf8(s);
- }
- if (cache == null) {
- cache = new LinkedHashMap<String,
ConstantUtf8>(INITIAL_CACHE_CAPACITY, 0.75f, true) {
- private static final long serialVersionUID = 1L;
-
- @Override
- protected boolean removeEldestEntry(Map.Entry<String,
ConstantUtf8> eldest) {
- return size() > MAX_CACHE_ENTRIES;
- }
- };
- }
- ConstantUtf8 result = cache.get(s);
- if (result != null) {
- return result;
- }
- result = new ConstantUtf8(s);
- cache.put(s, result);
- return result;
- }
-
- private static ConstantUtf8 getInstance(String s) {
- return getCachedInstance(s);
- }
static ConstantUtf8 getInstance(DataInputStream file) throws IOException {
- return getInstance(file.readUTF());
+ return new ConstantUtf8(file.readUTF());
}
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=1624535&r1=1624534&r2=1624535&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:12:21 2014
@@ -18,11 +18,9 @@
package org.apache.tomcat.util.bcel.classfile;
import java.io.DataInput;
-import java.io.DataInputStream;
+import java.io.EOFException;
import java.io.IOException;
-import org.apache.tomcat.util.bcel.Constants;
-
/**
* Utility functions that do not really belong to any class in particular.
*
@@ -47,426 +45,33 @@ final class Utility {
return str.replace('/', '.'); // Is `/' on all systems, even DOS
}
- static void swallowBootstrapMethods(DataInput file) throws IOException {
- int num_bootstrap_methods = file.readUnsignedShort();
- for (int i = 0; i < num_bootstrap_methods; i++) {
- file.readUnsignedShort(); // Unused bootstrap_method_ref
- int num_bootstrap_args = file.readUnsignedShort();
- for (int j = 0; j < num_bootstrap_args; j++) {
- file.readUnsignedShort(); // Unused bootstrap method argument
- }
- }
- }
-
- static void swallowMethodParameters(DataInput file) throws IOException {
- int parameters_count = file.readUnsignedByte();
- for (int i = 0; i < parameters_count; i++) {
- file.readUnsignedShort(); // Unused name_index
- file.readUnsignedShort(); // Unused access_flags
- }
- }
-
- static void swallowCodeException(DataInput file) throws IOException {
- file.readUnsignedShort(); // Unused start_pc
- file.readUnsignedShort(); // Unused end_pc
- file.readUnsignedShort(); // Unused handler_pc
- file.readUnsignedShort(); // Unused catch_type
- }
-
- static void swallowInnerClass(DataInput file) throws IOException {
- file.readUnsignedShort(); // Unused inner_class_index
- file.readUnsignedShort(); // Unused outer_class_index
- file.readUnsignedShort(); // Unused inner_name_index
- file.readUnsignedShort(); // Unused inner_access_flags
- }
-
- static void swallowLineNumber(DataInput file) throws IOException {
- file.readUnsignedShort(); // Unused start_pc
- file.readUnsignedShort(); // Unused line_number
- }
-
- static void swallowLocalVariable(DataInput file) throws IOException {
- file.readUnsignedShort(); // Unused start_pc
- file.readUnsignedShort(); // Unused length
- file.readUnsignedShort(); // Unused name_index
- file.readUnsignedShort(); // Unused signature_index
- file.readUnsignedShort(); // Unused index
- }
-
- static void swallowStackMap(DataInput file) throws IOException {
- int map_length = file.readUnsignedShort();
- for (int i = 0; i < map_length; i++) {
- swallowStackMapEntry(file);
- }
- }
-
- static void swallowStackMapTable(DataInputStream file) throws IOException {
- int map_length = file.readUnsignedShort();
- for (int i = 0; i < map_length; i++) {
- swallowStackMapTableEntry(file);
- }
- }
-
- static void swallowStackMapType(DataInput file) throws IOException {
- byte type = file.readByte();
- if ((type < Constants.ITEM_Bogus) || (type >
Constants.ITEM_NewObject)) {
- throw new ClassFormatException("Illegal type for StackMapType: " +
type);
- }
- // Check to see if type has an index
- if ((type == Constants.ITEM_Object) || (type ==
Constants.ITEM_NewObject)) {
- file.readShort(); // Unused index
- }
- }
-
- static void swallowStackMapEntry(DataInput file) throws IOException {
- file.readShort(); // Unused byte_code_offset
- int number_of_locals = file.readShort();
- for (int i = 0; i < number_of_locals; i++) {
- swallowStackMapType(file);
- }
- int number_of_stack_items = file.readShort();
- for (int i = 0; i < number_of_stack_items; i++) {
- swallowStackMapType(file);
- }
- }
-
- static void swallowStackMapTableEntry(DataInputStream file) throws
IOException {
- int frame_type = file.read();
-
- if (frame_type >= Constants.SAME_FRAME && frame_type <=
Constants.SAME_FRAME_MAX) {
- // NO-OP
- } else if (frame_type >= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME &&
- frame_type <= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX) {
- 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
- 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
- } else if (frame_type == Constants.SAME_FRAME_EXTENDED) {
- file.readShort(); // Unused byte_code_offset_delta
- } else if (frame_type >= Constants.APPEND_FRAME &&
- frame_type <= Constants.APPEND_FRAME_MAX) {
- file.readShort(); // Unused byte_code_offset_delta
- int number_of_locals = frame_type - 251;
- for (int i = 0; i < number_of_locals; i++) {
- 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++) {
- swallowStackMapType(file);
- }
- int number_of_stack_items = file.readShort();
- for (int i = 0; i < number_of_stack_items; i++) {
- swallowStackMapType(file);
- }
- } else {
- /* Can't happen */
- throw new ClassFormatException (
- "Invalid frame type found while parsing stack map table: "
+ frame_type);
- }
- }
-
- static void swallowUnknownAttribute(DataInput file, int length) throws
IOException {
- if (length > 0) {
- byte[] bytes = new byte[length];
- file.readFully(bytes);
- }
- }
-
- static void swallowSignature(DataInput file) throws IOException {
- file.readUnsignedShort(); // Unused signature_index
- }
-
- static void swallowSynthetic(int length) {
- if (length > 0) {
- throw new ClassFormatException("Synthetic attribute with length >
0");
- }
- }
-
- static void swallowSourceFile(DataInput file) throws IOException {
- file.readUnsignedShort(); // Unused sourcefile_index
- }
-
- static void swallowConstantValue(DataInput file) throws IOException {
- file.readUnsignedShort(); // Unused constantvalue_index
- }
-
- static void swallowCode(DataInputStream file, ConstantPool constant_pool)
throws IOException {
- file.readUnsignedShort(); // Unused max_stack
- file.readUnsignedShort(); // Unused max_locals
- int code_length = file.readInt();
- byte[] code = new byte[code_length]; // Read byte code
- file.readFully(code);
- /* Read exception table that contains all regions where an exception
- * handler is active, i.e., a try { ... } catch() block.
- */
- int exception_table_length = file.readUnsignedShort();
- for (int i = 0; i < exception_table_length; i++) {
- swallowCodeException(file);
- }
- /* Read all attributes, currently `LineNumberTable' and
- * `LocalVariableTable'
- */
- int attributes_count = file.readUnsignedShort();
- for (int i = 0; i < attributes_count; i++) {
- swallowAttribute(file, constant_pool);
- }
- }
-
- static void swallowExceptionTable(DataInput file) throws IOException {
- int number_of_exceptions = file.readUnsignedShort();
- for (int i = 0; i < number_of_exceptions; i++) {
- file.readUnsignedShort(); // Unused exception index
+ static void skipFully(DataInput file, int length) throws IOException {
+ int total = file.skipBytes(length);
+ if (total != length) {
+ throw new EOFException();
}
}
- static void swallowLineNumberTable(DataInput file) throws IOException {
- int line_number_table_length = (file.readUnsignedShort());
- for (int i = 0; i < line_number_table_length; i++) {
- 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++) {
- 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++) {
- swallowLocalVariable(file);
- }
- }
-
- static void swallowInnerClasses(DataInput file) throws IOException {
- int number_of_classes = file.readUnsignedShort();
- for (int i = 0; i < number_of_classes; i++) {
- swallowInnerClass(file);
- }
- }
-
- static void swallowDeprecated(int length) {
- if (length > 0) {
- throw new ClassFormatException("Deprecated attribute with length >
0");
- }
- }
-
- static void swallowPMCClass(DataInput file) throws IOException {
- file.readUnsignedShort(); // Unused pmg_index
- file.readUnsignedShort(); // Unused pmg_class_index
- }
-
- static void swallowEnclosingMethod(DataInput file) throws IOException {
- file.readUnsignedShort(); // Unused class index
- file.readUnsignedShort(); // Unused method index
- }
-
- static void swallowConstantCP(DataInput file) throws IOException {
- file.readUnsignedShort(); // Unused class index
- file.readUnsignedShort(); // Unused name and type index
- }
-
- static void swallowConstantMethodHandle(DataInput file) throws IOException
{
- file.readUnsignedByte(); // Unused reference_kind
- file.readUnsignedShort(); // Unused reference_index
- }
-
- static void swallowConstantString(DataInput file) throws IOException {
- file.readUnsignedShort(); // Unused string index
- }
-
- static void swallowConstantNameAndType(DataInput file) throws IOException {
- file.readUnsignedShort(); // Unused name index
- file.readUnsignedShort(); // Unused signature index
- }
-
- static void swallowConstantMethodType(DataInput file) throws IOException {
- file.readUnsignedShort(); // Unused descriptor_index
- }
-
- static void swallowConstantInvokeDynamic(DataInput file) throws
IOException {
- 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)
+ static void swallowFieldOrMethod(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
+ // file.readUnsignedShort(); // Unused access flags
+ // file.readUnsignedShort(); // name index
+ // file.readUnsignedShort(); // signature index
+ skipFully(file, 6);
int attributes_count = file.readUnsignedShort();
for (int i = 0; i < attributes_count; i++) {
- swallowAttribute(file, constant_pool);
+ swallowAttribute(file);
}
}
- static void swallowAttribute(DataInputStream file, ConstantPool
constant_pool)
+ static void swallowAttribute(DataInput file)
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();
+ //file.readUnsignedShort(); // Unused name index
+ skipFully(file, 2);
// 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);
- }
+ skipFully(file, length);
}
- static void swallowAnnotationDefault(DataInput file) throws IOException {
- swallowElementValue(file);
- }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]