View | Details | Raw Unified | Return to bug 56955
Collapse All | Expand All

(-)a/java/org/apache/tomcat/util/bcel/Constants.java (-7 / +5 lines)
Lines 20-25 package org.apache.tomcat.util.bcel; Link Here
20
/**
20
/**
21
 * Constants for the project, mostly defined in the JVM specification.
21
 * Constants for the project, mostly defined in the JVM specification.
22
 *
22
 *
23
 * @version $Id$
23
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24
 */
25
 */
25
public interface Constants {
26
public interface Constants {
Lines 511-527 public interface Constants { Link Here
511
  public static final byte ATTR_SIGNATURE                               = 10;
512
  public static final byte ATTR_SIGNATURE                               = 10;
512
  public static final byte ATTR_STACK_MAP                               = 11;
513
  public static final byte ATTR_STACK_MAP                               = 11;
513
  public static final byte ATTR_RUNTIME_VISIBLE_ANNOTATIONS             = 12;
514
  public static final byte ATTR_RUNTIME_VISIBLE_ANNOTATIONS             = 12;
514
  public static final byte ATTR_RUNTIME_INVISIBLE_ANNOTATIONS           = 13;
515
  public static final byte ATTR_RUNTIMEIN_VISIBLE_ANNOTATIONS           = 13;
515
  public static final byte ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS   = 14;
516
  public static final byte ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS   = 14;
516
  public static final byte ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS = 15;
517
  public static final byte ATTR_RUNTIMEIN_VISIBLE_PARAMETER_ANNOTATIONS = 15;
517
  public static final byte ATTR_ANNOTATION_DEFAULT                      = 16;
518
  public static final byte ATTR_ANNOTATION_DEFAULT                      = 16;
518
  public static final byte ATTR_LOCAL_VARIABLE_TYPE_TABLE               = 17;
519
  public static final byte ATTR_LOCAL_VARIABLE_TYPE_TABLE               = 17;
519
  public static final byte ATTR_ENCLOSING_METHOD                        = 18;
520
  public static final byte ATTR_ENCLOSING_METHOD                        = 18;
520
  public static final byte ATTR_STACK_MAP_TABLE                         = 19;
521
  public static final byte ATTR_STACK_MAP_TABLE                         = 19;
521
  public static final byte ATTR_BOOTSTRAP_METHODS                       = 20;
522
  public static final byte ATTR_METHOD_PARAMETERS                       = 21;
523
522
524
  public static final short KNOWN_ATTRIBUTES = 22;
523
  public static final short KNOWN_ATTRIBUTES = 20;
525
524
526
  // TOFO: FIXXXXX
525
  // TOFO: FIXXXXX
527
  public static final String[] ATTRIBUTE_NAMES = {
526
  public static final String[] ATTRIBUTE_NAMES = {
Lines 531-538 public interface Constants { Link Here
531
    "PMGClass", "Signature", "StackMap", 
530
    "PMGClass", "Signature", "StackMap", 
532
    "RuntimeVisibleAnnotations", "RuntimeInvisibleAnnotations",
531
    "RuntimeVisibleAnnotations", "RuntimeInvisibleAnnotations",
533
    "RuntimeVisibleParameterAnnotations", "RuntimeInvisibleParameterAnnotations",
532
    "RuntimeVisibleParameterAnnotations", "RuntimeInvisibleParameterAnnotations",
534
    "AnnotationDefault", "LocalVariableTypeTable", "EnclosingMethod", "StackMapTable",
533
    "AnnotationDefault", "LocalVariableTypeTable", "EnclosingMethod", "StackMapTable"
535
    "BootstrapMethods", "MethodParameters"
536
  };
534
  };
537
535
538
  /** Constants used in the StackMap attribute.
536
  /** Constants used in the StackMap attribute.
(-)a/java/org/apache/tomcat/util/bcel/classfile/AccessFlags.java (+1 lines)
Lines 21-26 package org.apache.tomcat.util.bcel.classfile; Link Here
21
 * Super class for all objects that have modifiers like private, final, ...
21
 * Super class for all objects that have modifiers like private, final, ...
22
 * I.e. classes, fields, and methods.
22
 * I.e. classes, fields, and methods.
23
 *
23
 *
24
 * @version $Id$
24
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
25
 */
26
 */
26
public abstract class AccessFlags implements java.io.Serializable {
27
public abstract class AccessFlags implements java.io.Serializable {
(-)a/java/org/apache/tomcat/util/bcel/classfile/AnnotationDefault.java (-3 / +12 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 25-32 import org.apache.tomcat.util.bcel.Constants; Link Here
25
/**
25
/**
26
 * represents the default value of a annotation for a method info
26
 * represents the default value of a annotation for a method info
27
 * 
27
 * 
28
 * @version $Id: AnnotationDefault 1 2005-02-13 03:15:08Z dbrosius $
28
 * @author <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
29
 * @author <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
29
 * @since 6.0
30
 * @since 5.3
30
 */
31
 */
31
public class AnnotationDefault extends Attribute
32
public class AnnotationDefault extends Attribute
32
{
33
{
Lines 44-56 public class AnnotationDefault extends Attribute Link Here
44
     *            Array of constants
45
     *            Array of constants
45
     */
46
     */
46
    public AnnotationDefault(int name_index, int length,
47
    public AnnotationDefault(int name_index, int length,
47
            DataInputStream file, ConstantPool constant_pool)
48
            DataInput file, ConstantPool constant_pool)
48
            throws IOException
49
            throws IOException
49
    {
50
    {
50
        this(name_index, length, (ElementValue) null,
51
        this(name_index, length, (ElementValue) null,
51
                constant_pool);
52
                constant_pool);
52
        default_value = ElementValue.readElementValue(file, constant_pool);
53
        default_value = ElementValue.readElementValue(file, constant_pool);
53
    }
54
    }
55
    
56
    public static void skip(int name_index, int length,
57
            DataInput file, ConstantPool constant_pool)
58
            throws IOException
59
    {
60
    	ElementValue.skipElementValue(file, constant_pool);
61
    }
62
54
63
55
    /**
64
    /**
56
     * @param name_index
65
     * @param name_index
(-)a/java/org/apache/tomcat/util/bcel/classfile/AnnotationElementValue.java (-4 / +3 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataOutputStream;
20
import java.io.DataOutput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
public class AnnotationElementValue extends ElementValue
23
public class AnnotationElementValue extends ElementValue
Lines 29-43 public class AnnotationElementValue extends ElementValue Link Here
29
            ConstantPool cpool)
29
            ConstantPool cpool)
30
    {
30
    {
31
        super(type, cpool);
31
        super(type, cpool);
32
        if (type != ANNOTATION) {
32
        if (type != ANNOTATION)
33
            throw new RuntimeException(
33
            throw new RuntimeException(
34
                    "Only element values of type annotation can be built with this ctor - type specified: " + type);
34
                    "Only element values of type annotation can be built with this ctor - type specified: " + type);
35
        }
36
        this.annotationEntry = annotationEntry;
35
        this.annotationEntry = annotationEntry;
37
    }
36
    }
38
37
39
    @Override
38
    @Override
40
    public void dump(DataOutputStream dos) throws IOException
39
    public void dump(DataOutput dos) throws IOException
41
    {
40
    {
42
        dos.writeByte(type); // u1 type of value (ANNOTATION == '@')
41
        dos.writeByte(type); // u1 type of value (ANNOTATION == '@')
43
        annotationEntry.dump(dos);
42
        annotationEntry.dump(dos);
(-)a/java/org/apache/tomcat/util/bcel/classfile/AnnotationEntry.java (-8 / +16 lines)
Lines 17-26 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.*;
21
import java.io.DataOutputStream;
22
import java.io.IOException;
23
import java.io.Serializable;
24
import java.util.ArrayList;
21
import java.util.ArrayList;
25
import java.util.List;
22
import java.util.List;
26
23
Lines 29-36 import org.apache.tomcat.util.bcel.Constants; Link Here
29
/**
26
/**
30
 * represents one annotation in the annotation table
27
 * represents one annotation in the annotation table
31
 * 
28
 * 
29
 * @version $Id: AnnotationEntry
32
 * @author  <A HREF="mailto:dbrosius@mebigfatguy.com">D. Brosius</A>
30
 * @author  <A HREF="mailto:dbrosius@mebigfatguy.com">D. Brosius</A>
33
 * @since 6.0
31
 * @since 5.3
34
 */
32
 */
35
public class AnnotationEntry implements Constants, Serializable {
33
public class AnnotationEntry implements Constants, Serializable {
36
34
Lines 42-55 public class AnnotationEntry implements Constants, Serializable { Link Here
42
    private List<ElementValuePair> element_value_pairs;
40
    private List<ElementValuePair> element_value_pairs;
43
    
41
    
44
    /**
42
    /**
45
     * Factory method to create an AnnotionEntry from a DataInputStream
43
     * Factory method to create an AnnotionEntry from a DataInput
46
     * 
44
     * 
47
     * @param file
45
     * @param file
48
     * @param constant_pool
46
     * @param constant_pool
49
     * @return the entry
47
     * @return the entry
50
     * @throws IOException
48
     * @throws IOException
51
     */
49
     */
52
    public static AnnotationEntry read(DataInputStream file, ConstantPool constant_pool) throws IOException {
50
    public static AnnotationEntry read(DataInput file, ConstantPool constant_pool) throws IOException {
53
        
51
        
54
        final AnnotationEntry annotationEntry = new AnnotationEntry(file.readUnsignedShort(), constant_pool);
52
        final AnnotationEntry annotationEntry = new AnnotationEntry(file.readUnsignedShort(), constant_pool);
55
        final int num_element_value_pairs = (file.readUnsignedShort());
53
        final int num_element_value_pairs = (file.readUnsignedShort());
Lines 60-65 public class AnnotationEntry implements Constants, Serializable { Link Here
60
        }
58
        }
61
        return annotationEntry;
59
        return annotationEntry;
62
    }
60
    }
61
    
62
    public static void skip(DataInput file, ConstantPool constant_pool) throws IOException {
63
//        final AnnotationEntry annotationEntry = new AnnotationEntry(file.readUnsignedShort(), constant_pool);
64
    	file.skipBytes(2);
65
    	int num_element_value_pairs = (file.readUnsignedShort());
66
        for (int i = 0; i < num_element_value_pairs; i++) {
67
        	file.skipBytes(2);
68
        	ElementValue.skipElementValue(file, constant_pool);
69
        }
70
    }
63
71
64
    public AnnotationEntry(int type_index, ConstantPool constant_pool) {
72
    public AnnotationEntry(int type_index, ConstantPool constant_pool) {
65
        this.type_index = type_index;
73
        this.type_index = type_index;
Lines 82-88 public class AnnotationEntry implements Constants, Serializable { Link Here
82
        return element_value_pairs.toArray(new ElementValuePair[element_value_pairs.size()]);
90
        return element_value_pairs.toArray(new ElementValuePair[element_value_pairs.size()]);
83
    }
91
    }
84
92
85
    public void dump(DataOutputStream dos) throws IOException {
93
    public void dump(DataOutput dos) throws IOException {
86
        dos.writeShort(type_index); // u2 index of type name in cpool
94
        dos.writeShort(type_index); // u2 index of type name in cpool
87
        dos.writeShort(element_value_pairs.size()); // u2 element_value pair
95
        dos.writeShort(element_value_pairs.size()); // u2 element_value pair
88
        // count
96
        // count
(-)a/java/org/apache/tomcat/util/bcel/classfile/Annotations.java (-5 / +13 lines)
Lines 17-31 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.DataOutputStream;
21
import java.io.DataOutput;
22
import java.io.IOException;
22
import java.io.IOException;
23
23
24
/**
24
/**
25
 * base class for annotations
25
 * base class for annotations
26
 * 
26
 * 
27
 * @version $Id: Annotations
27
 * @author  <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
28
 * @author  <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
28
 * @since 6.0
29
 * @since 5.3
29
 */
30
 */
30
public abstract class Annotations extends Attribute {
31
public abstract class Annotations extends Attribute {
31
32
Lines 40-46 public abstract class Annotations extends Attribute { Link Here
40
     * @param file Input stream
41
     * @param file Input stream
41
     * @param constant_pool Array of constants
42
     * @param constant_pool Array of constants
42
     */
43
     */
43
    public Annotations(byte annotation_type, int name_index, int length, DataInputStream file, ConstantPool constant_pool) throws IOException {
44
    public Annotations(byte annotation_type, int name_index, int length, DataInput file, ConstantPool constant_pool) throws IOException {
44
        this(annotation_type, name_index, length, (AnnotationEntry[]) null, constant_pool);
45
        this(annotation_type, name_index, length, (AnnotationEntry[]) null, constant_pool);
45
        final int annotation_table_length = (file.readUnsignedShort());
46
        final int annotation_table_length = (file.readUnsignedShort());
46
        annotation_table = new AnnotationEntry[annotation_table_length];
47
        annotation_table = new AnnotationEntry[annotation_table_length];
Lines 48-53 public abstract class Annotations extends Attribute { Link Here
48
            annotation_table[i] = AnnotationEntry.read(file, constant_pool);
49
            annotation_table[i] = AnnotationEntry.read(file, constant_pool);
49
        }
50
        }
50
    }
51
    }
52
    
53
    public static void skip(byte annotation_type, int name_index, int length, DataInput file, ConstantPool constant_pool) throws IOException {
54
    	int annotation_table_length = (file.readUnsignedShort());
55
        for (int i = 0; i < annotation_table_length; i++) {
56
        	AnnotationEntry.skip(file, constant_pool);
57
        }
58
    }
51
59
52
60
53
    /**
61
    /**
Lines 76-82 public abstract class Annotations extends Attribute { Link Here
76
        return annotation_table;
84
        return annotation_table;
77
    }
85
    }
78
86
79
    protected void writeAnnotations(DataOutputStream dos) throws IOException {
87
    protected void writeAnnotations(DataOutput dos) throws IOException {
80
        if (annotation_table == null) {
88
        if (annotation_table == null) {
81
            return;
89
            return;
82
        }
90
        }
(-)a/java/org/apache/tomcat/util/bcel/classfile/ArrayElementValue.java (-6 / +4 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataOutputStream;
20
import java.io.DataOutput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
public class ArrayElementValue extends ElementValue
23
public class ArrayElementValue extends ElementValue
Lines 43-57 public class ArrayElementValue extends ElementValue Link Here
43
    public ArrayElementValue(int type, ElementValue[] datums, ConstantPool cpool)
43
    public ArrayElementValue(int type, ElementValue[] datums, ConstantPool cpool)
44
    {
44
    {
45
        super(type, cpool);
45
        super(type, cpool);
46
        if (type != ARRAY) {
46
        if (type != ARRAY)
47
            throw new RuntimeException(
47
            throw new RuntimeException(
48
                    "Only element values of type array can be built with this ctor - type specified: " + type);
48
                    "Only element values of type array can be built with this ctor - type specified: " + type);
49
        }
50
        this.evalues = datums;
49
        this.evalues = datums;
51
    }
50
    }
52
51
53
    @Override
52
    @Override
54
    public void dump(DataOutputStream dos) throws IOException
53
    public void dump(DataOutput dos) throws IOException
55
    {
54
    {
56
        dos.writeByte(type); // u1 type of value (ARRAY == '[')
55
        dos.writeByte(type); // u1 type of value (ARRAY == '[')
57
        dos.writeShort(evalues.length);
56
        dos.writeShort(evalues.length);
Lines 69-77 public class ArrayElementValue extends ElementValue Link Here
69
        for (int i = 0; i < evalues.length; i++)
68
        for (int i = 0; i < evalues.length; i++)
70
        {
69
        {
71
            sb.append(evalues[i].stringifyValue());
70
            sb.append(evalues[i].stringifyValue());
72
            if ((i + 1) < evalues.length) {
71
            if ((i + 1) < evalues.length)
73
                sb.append(",");
72
                sb.append(",");
74
            }
75
        }
73
        }
76
        sb.append("]");
74
        sb.append("]");
77
        return sb.toString();
75
        return sb.toString();
(-)a/java/org/apache/tomcat/util/bcel/classfile/Attribute.java (-10 / +144 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
import java.io.Serializable;
22
import java.io.Serializable;
23
import java.util.HashMap;
23
import java.util.HashMap;
Lines 33-38 import org.apache.tomcat.util.bcel.Constants; Link Here
33
 * <em>Synthetic</em> attributes are supported. The <em>Unknown</em>
33
 * <em>Synthetic</em> attributes are supported. The <em>Unknown</em>
34
 * attribute stands for non-standard-attributes.
34
 * attribute stands for non-standard-attributes.
35
 * 
35
 * 
36
 * @version $Id$
36
 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
37
 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
37
 * @see ConstantValue
38
 * @see ConstantValue
38
 * @see SourceFile
39
 * @see SourceFile
Lines 80-86 public abstract class Attribute implements Cloneable, Serializable Link Here
80
     *      constants @return Attribute @throws IOException @throws
81
     *      constants @return Attribute @throws IOException @throws
81
     *      ClassFormatException
82
     *      ClassFormatException
82
     */
83
     */
83
    public static final Attribute readAttribute(DataInputStream file,
84
    public static final Attribute readAttribute(DataInput file,
84
            ConstantPool constant_pool) throws IOException,
85
            ConstantPool constant_pool) throws IOException,
85
            ClassFormatException
86
            ClassFormatException
86
    {
87
    {
Lines 145-157 public abstract class Attribute implements Cloneable, Serializable Link Here
145
        case Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS:
146
        case Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS:
146
            return new RuntimeVisibleAnnotations(name_index, length, file,
147
            return new RuntimeVisibleAnnotations(name_index, length, file,
147
                    constant_pool);
148
                    constant_pool);
148
        case Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS:
149
        case Constants.ATTR_RUNTIMEIN_VISIBLE_ANNOTATIONS:
149
            return new RuntimeInvisibleAnnotations(name_index, length, file,
150
            return new RuntimeInvisibleAnnotations(name_index, length, file,
150
                    constant_pool);
151
                    constant_pool);
151
        case Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS:
152
        case Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS:
152
            return new RuntimeVisibleParameterAnnotations(name_index, length,
153
            return new RuntimeVisibleParameterAnnotations(name_index, length,
153
                    file, constant_pool);
154
                    file, constant_pool);
154
        case Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS:
155
        case Constants.ATTR_RUNTIMEIN_VISIBLE_PARAMETER_ANNOTATIONS:
155
            return new RuntimeInvisibleParameterAnnotations(name_index, length,
156
            return new RuntimeInvisibleParameterAnnotations(name_index, length,
156
                    file, constant_pool);
157
                    file, constant_pool);
157
        case Constants.ATTR_ANNOTATION_DEFAULT:
158
        case Constants.ATTR_ANNOTATION_DEFAULT:
Lines 164-175 public abstract class Attribute implements Cloneable, Serializable Link Here
164
            return new EnclosingMethod(name_index, length, file, constant_pool);
165
            return new EnclosingMethod(name_index, length, file, constant_pool);
165
        case Constants.ATTR_STACK_MAP_TABLE:
166
        case Constants.ATTR_STACK_MAP_TABLE:
166
            return new StackMapTable(name_index, length, file, constant_pool);
167
            return new StackMapTable(name_index, length, file, constant_pool);
167
        case Constants.ATTR_BOOTSTRAP_METHODS:
168
            Utility.swallowBootstrapMethods(file);
169
            return null;
170
        case Constants.ATTR_METHOD_PARAMETERS:
171
            Utility.swallowMethodParameters(file);
172
            return null;
173
        default: // Never reached
168
        default: // Never reached
174
            throw new IllegalStateException("Unrecognized attribute type tag parsed: " + tag);
169
            throw new IllegalStateException("Unrecognized attribute type tag parsed: " + tag);
175
        }
170
        }
Lines 230-233 public abstract class Attribute implements Cloneable, Serializable Link Here
230
    {
225
    {
231
        return Constants.ATTRIBUTE_NAMES[tag];
226
        return Constants.ATTRIBUTE_NAMES[tag];
232
    }
227
    }
228
    
229
    public static final void skipAttribute(DataInput file,
230
            ConstantPool constant_pool) throws IOException,
231
            ClassFormatException
232
    {
233
        ConstantUtf8 c;
234
        String name;
235
        int name_index;
236
        int length;
237
        byte tag = Constants.ATTR_UNKNOWN; // Unknown attribute
238
        // Get class name from constant pool via `name_index' indirection
239
        name_index = file.readUnsignedShort();
240
        c = (ConstantUtf8) constant_pool.getConstant(name_index,
241
                Constants.CONSTANT_Utf8);
242
        name = c.getBytes();
243
        // Length of data in bytes
244
        length = file.readInt();
245
        // Compare strings to find known attribute
246
        // System.out.println(name);
247
        for (byte i = 0; i < Constants.KNOWN_ATTRIBUTES; i++)
248
        {
249
            if (name.equals(Constants.ATTRIBUTE_NAMES[i]))
250
            {
251
                tag = i; // found!
252
                break;
253
            }
254
        }
255
        // Call proper constructor, depending on `tag'
256
        switch (tag)
257
        {
258
        case Constants.ATTR_UNKNOWN:
259
//        	AttributeReader r = readers.get(name);
260
//            if (r != null)
261
//            {
262
//                return r.createAttribute(name_index, length, file,
263
//                        constant_pool);
264
//            }
265
//            return new Unknown(name_index, length, file, constant_pool);
266
            AttributeReader r = readers.get(name);
267
            if (r != null)
268
            {
269
            	// how to skip this case???????????????????????????
270
                r.createAttribute(name_index, length, file,
271
                        constant_pool);
272
                return;
273
            }
274
            Unknown.skip(name_index, length, file, constant_pool);
275
            return;
276
        case Constants.ATTR_CONSTANT_VALUE:
277
//            return new ConstantValue(name_index, length, file, constant_pool);
278
        	ConstantValue.skip(name_index, length, file, constant_pool);
279
        	return;
280
        case Constants.ATTR_SOURCE_FILE:
281
//            return new SourceFile(name_index, length, file, constant_pool);
282
        	SourceFile.skip(name_index, length, file, constant_pool);
283
        	return;
284
        case Constants.ATTR_CODE:
285
//            return new Code(name_index, length, file, constant_pool);
286
            Code.skip(name_index, length, file, constant_pool);
287
            return;
288
        case Constants.ATTR_EXCEPTIONS:
289
//            return new ExceptionTable(name_index, length, file, constant_pool);
290
            ExceptionTable.skip(name_index, length, file, constant_pool);
291
            return;
292
        case Constants.ATTR_LINE_NUMBER_TABLE:
293
//            return new LineNumberTable(name_index, length, file, constant_pool);
294
            LineNumberTable.skip(name_index, length, file, constant_pool);
295
            return;
296
        case Constants.ATTR_LOCAL_VARIABLE_TABLE:
297
//            return new LocalVariableTable(name_index, length, file,
298
//                    constant_pool);
299
            LocalVariableTable.skip(name_index, length, file, constant_pool);
300
            return;
301
        case Constants.ATTR_INNER_CLASSES:
302
//            return new InnerClasses(name_index, length, file, constant_pool);
303
            InnerClasses.skip(name_index, length, file, constant_pool);
304
            return;
305
        case Constants.ATTR_SYNTHETIC:
306
//            return new Synthetic(name_index, length, file, constant_pool);
307
            Synthetic.skip(name_index, length, file, constant_pool);
308
            return;
309
        case Constants.ATTR_DEPRECATED:
310
//            return new Deprecated(name_index, length, file, constant_pool);
311
            Deprecated.skip(name_index, length, file, constant_pool);
312
            return;
313
        case Constants.ATTR_PMG:
314
//            return new PMGClass(name_index, length, file, constant_pool);
315
            PMGClass.skip(name_index, length, file, constant_pool);
316
            return;
317
        case Constants.ATTR_SIGNATURE:
318
//            return new Signature(name_index, length, file, constant_pool);
319
            Signature.skip(name_index, length, file, constant_pool);
320
            return;
321
        case Constants.ATTR_STACK_MAP:
322
//            return new StackMap(name_index, length, file, constant_pool);
323
            StackMap.skip(name_index, length, file, constant_pool);
324
            return;
325
        case Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS:
326
//            return new RuntimeVisibleAnnotations(name_index, length, file,
327
//                    constant_pool);
328
            RuntimeVisibleAnnotations.skip(name_index, length, file, constant_pool);
329
            return;
330
        case Constants.ATTR_RUNTIMEIN_VISIBLE_ANNOTATIONS:
331
//            return new RuntimeInvisibleAnnotations(name_index, length, file,
332
//                    constant_pool);
333
            RuntimeInvisibleAnnotations.skip(name_index, length, file, constant_pool);
334
            return;
335
        case Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS:
336
//            return new RuntimeVisibleParameterAnnotations(name_index, length,
337
//                    file, constant_pool);
338
            RuntimeVisibleParameterAnnotations.skip(name_index, length, file, constant_pool);
339
            return;
340
        case Constants.ATTR_RUNTIMEIN_VISIBLE_PARAMETER_ANNOTATIONS:
341
//            return new RuntimeInvisibleParameterAnnotations(name_index, length,
342
//                    file, constant_pool);
343
            RuntimeInvisibleParameterAnnotations.skip(name_index, length, file, constant_pool);
344
            return;
345
        case Constants.ATTR_ANNOTATION_DEFAULT:
346
//            return new AnnotationDefault(name_index, length, file,
347
//                    constant_pool);
348
            AnnotationDefault.skip(name_index, length, file, constant_pool);
349
            return;
350
        case Constants.ATTR_LOCAL_VARIABLE_TYPE_TABLE:
351
//            return new LocalVariableTypeTable(name_index, length, file,
352
//                    constant_pool);
353
            LocalVariableTypeTable.skip(name_index, length, file, constant_pool);
354
            return;
355
        case Constants.ATTR_ENCLOSING_METHOD:
356
//            return new EnclosingMethod(name_index, length, file, constant_pool);
357
            EnclosingMethod.skip(name_index, length, file, constant_pool);
358
            return;
359
        case Constants.ATTR_STACK_MAP_TABLE:
360
//            return new StackMapTable(name_index, length, file, constant_pool);
361
            StackMapTable.skip(name_index, length, file, constant_pool);
362
            return;
363
        default: // Never reached
364
            throw new IllegalStateException("Unrecognized attribute type tag parsed: " + tag);
365
        }
366
    }
233
}
367
}
(-)a/java/org/apache/tomcat/util/bcel/classfile/AttributeReader.java (-1 / +2 lines)
Lines 23-28 package org.apache.tomcat.util.bcel.classfile; Link Here
23
 * method. These factory objects should implement this interface.
23
 * method. These factory objects should implement this interface.
24
24
25
 * @see Attribute
25
 * @see Attribute
26
 * @version $Id$
26
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27
 */
28
 */
28
public interface AttributeReader {
29
public interface AttributeReader {
Lines 51-56 public interface AttributeReader { Link Here
51
     it to construct an attribute.  In the case of errors, a null can be
52
     it to construct an attribute.  In the case of errors, a null can be
52
     returned which will cause the parsing of the class file to fail.
53
     returned which will cause the parsing of the class file to fail.
53
     */
54
     */
54
    Attribute createAttribute( int name_index, int length, java.io.DataInputStream file,
55
    Attribute createAttribute( int name_index, int length, java.io.DataInput file,
55
            ConstantPool constant_pool );
56
            ConstantPool constant_pool );
56
}
57
}
(-)a/java/org/apache/tomcat/util/bcel/classfile/ClassElementValue.java (-1 / +2 lines)
Lines 17-22 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataOutput;
20
import java.io.DataOutputStream;
21
import java.io.DataOutputStream;
21
import java.io.IOException;
22
import java.io.IOException;
22
23
Lines 45-51 public class ClassElementValue extends ElementValue Link Here
45
    }
46
    }
46
47
47
    @Override
48
    @Override
48
    public void dump(DataOutputStream dos) throws IOException
49
    public void dump(DataOutput dos) throws IOException
49
    {
50
    {
50
        dos.writeByte(type); // u1 kind of value
51
        dos.writeByte(type); // u1 kind of value
51
        dos.writeShort(idx);
52
        dos.writeShort(idx);
(-)a/java/org/apache/tomcat/util/bcel/classfile/ClassFormatException.java (+1 lines)
Lines 22-27 package org.apache.tomcat.util.bcel.classfile; Link Here
22
 * that the file is malformed or otherwise cannot be interpreted as a
22
 * that the file is malformed or otherwise cannot be interpreted as a
23
 * class file.
23
 * class file.
24
 *
24
 *
25
 * @version $Id$
25
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26
 */
27
 */
27
public class ClassFormatException extends RuntimeException {
28
public class ClassFormatException extends RuntimeException {
(-)a/java/org/apache/tomcat/util/bcel/classfile/ClassParser.java (-102 / +126 lines)
Lines 17-31 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.BufferedInputStream;
20
import java.io.*;
21
import java.io.DataInputStream;
21
import java.util.Arrays;
22
import java.io.FileInputStream;
23
import java.io.IOException;
24
import java.io.InputStream;
25
import java.util.zip.ZipEntry;
22
import java.util.zip.ZipEntry;
26
import java.util.zip.ZipFile;
23
import java.util.zip.ZipFile;
27
24
28
import org.apache.tomcat.util.bcel.Constants;
25
import org.apache.tomcat.util.bcel.Constants;
26
import org.apache.tomcat.util.bcel.util.FastDataInputStream;
29
27
30
/**
28
/**
31
 * Wrapper class that parses a given Java .class file. The method <A
29
 * Wrapper class that parses a given Java .class file. The method <A
Lines 39-49 import org.apache.tomcat.util.bcel.Constants; Link Here
39
 * JVM specification 1.0</a>. See this paper for
37
 * JVM specification 1.0</a>. See this paper for
40
 * further details about the structure of a bytecode file.
38
 * further details about the structure of a bytecode file.
41
 *
39
 *
40
 * @version $Id$
42
 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A> 
41
 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A> 
43
 */
42
 */
44
public final class ClassParser {
43
public final class ClassParser {
44
	
45
	//switch for parse model
46
	public static boolean isSkip = false;
45
47
46
    private DataInputStream file;
48
    private DataInput file;
47
    private boolean fileOwned;
49
    private boolean fileOwned;
48
    private String file_name;
50
    private String file_name;
49
    private String zip_file;
51
    private String zip_file;
Lines 70-165 public final class ClassParser { Link Here
70
        fileOwned = false;
72
        fileOwned = false;
71
        String clazz = file.getClass().getName(); // Not a very clean solution ...
73
        String clazz = file.getClass().getName(); // Not a very clean solution ...
72
        is_zip = clazz.startsWith("java.util.zip.") || clazz.startsWith("java.util.jar.");
74
        is_zip = clazz.startsWith("java.util.zip.") || clazz.startsWith("java.util.jar.");
73
        if (file instanceof DataInputStream) {
75
        if (file instanceof FastDataInputStream) {
74
            this.file = (DataInputStream) file;
76
            this.file = (FastDataInputStream) file;
75
        } else {
77
        } else {
76
            this.file = new DataInputStream(new BufferedInputStream(file, BUFSIZE));
78
            this.file = new FastDataInputStream(file, BUFSIZE);
77
        }
79
        }
78
    }
80
    }
79
81
82
  public JavaClass parse() throws IOException, ClassFormatException {
83
  ZipFile zip = null;
84
  try {
85
      if (fileOwned) {
86
          if (is_zip) {
87
              zip = new ZipFile(zip_file);
88
              ZipEntry entry = zip.getEntry(file_name);
89
              
90
              if (entry == null) {
91
                  throw new IOException("File " + file_name + " not found");
92
              }
93
              
94
              file = new DataInputStream(new BufferedInputStream(zip.getInputStream(entry),
95
                      BUFSIZE));
96
          } else {
97
              file = new DataInputStream(new BufferedInputStream(new FileInputStream(
98
                      file_name), BUFSIZE));
99
          }
100
      }
101
      /****************** Read headers ********************************/
102
      // Check magic tag of class file
103
      readID();
104
      // Get compiler version
105
      if(!isSkip) readVersion();
106
      else skipVersion();
107
      /****************** Read constant pool and related **************/
108
      // Read constant pool entries
109
      readConstantPool();
110
      // Get class information
111
      readClassInfo();
112
      // Get interface information, i.e., implemented interfaces
113
      readInterfaces();
114
      /****************** Read class fields and methods ***************/
115
      // Read class fields, i.e., the variables of the class
116
      if(!isSkip) readFields();
117
      else skipFields();
118
      // Read class methods, i.e., the functions in the class
119
      if(!isSkip) readMethods();
120
      else skipMethods();
121
      // Read class attributes
122
      readAttributes();
123
      // Check for unknown variables
124
      //Unknown[] u = Unknown.getUnknownAttributes();
125
      //for(int i=0; i < u.length; i++)
126
      //  System.err.println("WARNING: " + u[i]);
127
      // Everything should have been read now
128
      //      if(file.available() > 0) {
129
      //        int bytes = file.available();
130
      //        byte[] buf = new byte[bytes];
131
      //        file.read(buf);
132
      //        if(!(is_zip && (buf.length == 1))) {
133
      //          System.err.println("WARNING: Trailing garbage at end of " + file_name);
134
      //          System.err.println(bytes + " extra bytes: " + Utility.toHexString(buf));
135
      //        }
136
      //      }
137
  } finally {
138
      // Read everything of interest, so close the file
139
      if (fileOwned) {
140
          try {
141
              if (file != null && file instanceof Closeable) {
142
                  ((Closeable)file).close();
143
              }
144
              if (zip != null) {
145
                  zip.close();
146
              }
147
          } catch (IOException ioe) {
148
              //ignore close exceptions
149
          }
150
      }
151
  }
152
  // Return the information we have gathered in a new object
153
  return new JavaClass(class_name_index, superclass_name_index, file_name, major, minor,
154
          access_flags, constant_pool, interfaces, fields, methods, attributes);
155
}
80
156
81
    /**
82
     * Parse the given Java class file and return an object that represents
83
     * the contained data, i.e., constants, methods, fields and commands.
84
     * A <em>ClassFormatException</em> is raised, if the file is not a valid
85
     * .class file. (This does not include verification of the byte code as it
86
     * is performed by the java interpreter).
87
     *
88
     * @return Class object representing the parsed class file
89
     * @throws  IOException
90
     * @throws  ClassFormatException
91
     */
92
    public JavaClass parse() throws IOException, ClassFormatException {
93
        ZipFile zip = null;
94
        try {
95
            if (fileOwned) {
96
                if (is_zip) {
97
                    zip = new ZipFile(zip_file);
98
                    ZipEntry entry = zip.getEntry(file_name);
99
                    
100
                    if (entry == null) {
101
                        throw new IOException("File " + file_name + " not found");
102
                    }
103
                    
104
                    file = new DataInputStream(new BufferedInputStream(zip.getInputStream(entry),
105
                            BUFSIZE));
106
                } else {
107
                    file = new DataInputStream(new BufferedInputStream(new FileInputStream(
108
                            file_name), BUFSIZE));
109
                }
110
            }
111
            /****************** Read headers ********************************/
112
            // Check magic tag of class file
113
            readID();
114
            // Get compiler version
115
            readVersion();
116
            /****************** Read constant pool and related **************/
117
            // Read constant pool entries
118
            readConstantPool();
119
            // Get class information
120
            readClassInfo();
121
            // Get interface information, i.e., implemented interfaces
122
            readInterfaces();
123
            /****************** Read class fields and methods ***************/
124
            // Read class fields, i.e., the variables of the class
125
            readFields();
126
            // Read class methods, i.e., the functions in the class
127
            readMethods();
128
            // Read class attributes
129
            readAttributes();
130
            // Check for unknown variables
131
            //Unknown[] u = Unknown.getUnknownAttributes();
132
            //for(int i=0; i < u.length; i++)
133
            //  System.err.println("WARNING: " + u[i]);
134
            // Everything should have been read now
135
            //      if(file.available() > 0) {
136
            //        int bytes = file.available();
137
            //        byte[] buf = new byte[bytes];
138
            //        file.read(buf);
139
            //        if(!(is_zip && (buf.length == 1))) {
140
            //          System.err.println("WARNING: Trailing garbage at end of " + file_name);
141
            //          System.err.println(bytes + " extra bytes: " + Utility.toHexString(buf));
142
            //        }
143
            //      }
144
        } finally {
145
            // Read everything of interest, so close the file
146
            if (fileOwned) {
147
                try {
148
                    if (file != null) {
149
                        file.close();
150
                    }
151
                    if (zip != null) {
152
                        zip.close();
153
                    }
154
                } catch (IOException ioe) {
155
                    //ignore close exceptions
156
                }
157
            }
158
        }
159
        // Return the information we have gathered in a new object
160
        return new JavaClass(class_name_index, superclass_name_index, file_name, major, minor,
161
                access_flags, constant_pool, interfaces, fields, methods, attributes);
162
    }
163
157
164
158
165
    /**
159
    /**
Lines 167-173 public final class ClassParser { Link Here
167
     * @throws  IOException
161
     * @throws  IOException
168
     * @throws  ClassFormatException
162
     * @throws  ClassFormatException
169
     */
163
     */
170
    private void readAttributes() throws IOException, ClassFormatException {
164
	private final void readAttributes() throws IOException, ClassFormatException {
171
        int attributes_count;
165
        int attributes_count;
172
        attributes_count = file.readUnsignedShort();
166
        attributes_count = file.readUnsignedShort();
173
        attributes = new Attribute[attributes_count];
167
        attributes = new Attribute[attributes_count];
Lines 182-188 public final class ClassParser { Link Here
182
     * @throws  IOException
176
     * @throws  IOException
183
     * @throws  ClassFormatException
177
     * @throws  ClassFormatException
184
     */
178
     */
185
    private void readClassInfo() throws IOException, ClassFormatException {
179
    private final void readClassInfo() throws IOException, ClassFormatException {
186
        access_flags = file.readUnsignedShort();
180
        access_flags = file.readUnsignedShort();
187
        /* Interfaces are implicitely abstract, the flag should be set
181
        /* Interfaces are implicitely abstract, the flag should be set
188
         * according to the JVM specification.
182
         * according to the JVM specification.
Lines 204-210 public final class ClassParser { Link Here
204
     * @throws  IOException
198
     * @throws  IOException
205
     * @throws  ClassFormatException
199
     * @throws  ClassFormatException
206
     */
200
     */
207
    private void readConstantPool() throws IOException, ClassFormatException {
201
    private final void readConstantPool() throws IOException, ClassFormatException {
208
        constant_pool = new ConstantPool(file);
202
        constant_pool = new ConstantPool(file);
209
    }
203
    }
210
204
Lines 214-220 public final class ClassParser { Link Here
214
     * @throws  IOException
208
     * @throws  IOException
215
     * @throws  ClassFormatException
209
     * @throws  ClassFormatException
216
     */
210
     */
217
    private void readFields() throws IOException, ClassFormatException {
211
    private final void readFields() throws IOException, ClassFormatException {
218
        int fields_count;
212
        int fields_count;
219
        fields_count = file.readUnsignedShort();
213
        fields_count = file.readUnsignedShort();
220
        fields = new Field[fields_count];
214
        fields = new Field[fields_count];
Lines 222-227 public final class ClassParser { Link Here
222
            fields[i] = new Field(file, constant_pool);
216
            fields[i] = new Field(file, constant_pool);
223
        }
217
        }
224
    }
218
    }
219
    
220
    private final void skipFields() throws IOException, ClassFormatException {
221
    	int fields_count;
222
        fields_count = file.readUnsignedShort();
223
        for (int i = 0; i < fields_count; i++) {
224
        	Field.skip(file, constant_pool);
225
        }
226
    }
227
228
    private static final byte[] MAGIC_ID = new byte[] { (byte)0xCA, (byte)0xFE, (byte)0xBA, (byte)0xBE};
225
229
226
230
227
    /******************** Private utility methods **********************/
231
    /******************** Private utility methods **********************/
Lines 231-242 public final class ClassParser { Link Here
231
     * @throws  IOException
235
     * @throws  IOException
232
     * @throws  ClassFormatException
236
     * @throws  ClassFormatException
233
     */
237
     */
234
    private void readID() throws IOException, ClassFormatException {
238
    private final void readID() throws IOException, ClassFormatException {
235
        int magic = 0xCAFEBABE;
239
        byte[] bytes = new byte[4];
236
        if (file.readInt() != magic) {
240
        file.readFully(bytes);
241
        if (!Arrays.equals(bytes, MAGIC_ID)) {
237
            throw new ClassFormatException(file_name + " is not a Java .class file");
242
            throw new ClassFormatException(file_name + " is not a Java .class file");
238
        }
243
        }
244
//        int magic = 0xCAFEBABE;
245
//        if (file.readInt() != magic) {
246
//            throw new ClassFormatException(file_name + " is not a Java .class file");
247
//        }
239
    }
248
    }
249
    
250
//    private final void skipID() throws IOException, ClassFormatException{
251
//    	file.skipBytes(4);    
252
//    }
240
253
241
254
242
    /**
255
    /**
Lines 244-250 public final class ClassParser { Link Here
244
     * @throws  IOException
257
     * @throws  IOException
245
     * @throws  ClassFormatException
258
     * @throws  ClassFormatException
246
     */
259
     */
247
    private void readInterfaces() throws IOException, ClassFormatException {
260
    private final void readInterfaces() throws IOException, ClassFormatException {
248
        int interfaces_count;
261
        int interfaces_count;
249
        interfaces_count = file.readUnsignedShort();
262
        interfaces_count = file.readUnsignedShort();
250
        interfaces = new int[interfaces_count];
263
        interfaces = new int[interfaces_count];
Lines 253-265 public final class ClassParser { Link Here
253
        }
266
        }
254
    }
267
    }
255
268
256
257
    /**
269
    /**
258
     * Read information about the methods of the class.
270
     * Read information about the methods of the class.
259
     * @throws  IOException
271
     * @throws  IOException
260
     * @throws  ClassFormatException
272
     * @throws  ClassFormatException
261
     */
273
     */
262
    private void readMethods() throws IOException, ClassFormatException {
274
    private final void readMethods() throws IOException, ClassFormatException {
263
        int methods_count;
275
        int methods_count;
264
        methods_count = file.readUnsignedShort();
276
        methods_count = file.readUnsignedShort();
265
        methods = new Method[methods_count];
277
        methods = new Method[methods_count];
Lines 267-272 public final class ClassParser { Link Here
267
            methods[i] = new Method(file, constant_pool);
279
            methods[i] = new Method(file, constant_pool);
268
        }
280
        }
269
    }
281
    }
282
    
283
    private final void skipMethods() throws IOException, ClassFormatException {
284
    	int methods_count;
285
        methods_count = file.readUnsignedShort();
286
        for (int i = 0; i < methods_count; i++) {
287
        	Method.skip(file, constant_pool);
288
        }
289
    }
270
290
271
291
272
    /**
292
    /**
Lines 274-281 public final class ClassParser { Link Here
274
     * @throws  IOException
294
     * @throws  IOException
275
     * @throws  ClassFormatException
295
     * @throws  ClassFormatException
276
     */
296
     */
277
    private void readVersion() throws IOException, ClassFormatException {
297
    private final void readVersion() throws IOException, ClassFormatException {
278
        minor = file.readUnsignedShort();
298
        minor = file.readUnsignedShort();
279
        major = file.readUnsignedShort();
299
        major = file.readUnsignedShort();
280
    }
300
    }
301
    
302
    private final void skipVersion() throws IOException, ClassFormatException {
303
        file.skipBytes(4);
304
    }
281
}
305
}
(-)a/java/org/apache/tomcat/util/bcel/classfile/Code.java (-6 / +28 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 34-39 import org.apache.tomcat.util.bcel.Constants; Link Here
34
 * is used for debugging purposes and <em>LocalVariableTable</em> which 
34
 * is used for debugging purposes and <em>LocalVariableTable</em> which 
35
 * contains information about the local variables.
35
 * contains information about the local variables.
36
 *
36
 *
37
 * @version $Id$
37
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
38
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
38
 * @see     Attribute
39
 * @see     Attribute
39
 * @see     CodeException
40
 * @see     CodeException
Lines 59-72 public final class Code extends Attribute { Link Here
59
     * @param file Input stream
60
     * @param file Input stream
60
     * @param constant_pool Array of constants
61
     * @param constant_pool Array of constants
61
     */
62
     */
62
    Code(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
63
	Code(int name_index, int length, DataInput file, ConstantPool constant_pool)
63
            throws IOException {
64
            throws IOException {
64
        // Initialize with some default values which will be overwritten later
65
    	// Initialize with some default values which will be overwritten later
65
        this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), (byte[]) null,
66
        this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), (byte[]) null,
66
                (CodeException[]) null, (Attribute[]) null, constant_pool);
67
                (CodeException[]) null, (Attribute[]) null, constant_pool);
68
//        System.out.println("init");
67
        code_length = file.readInt();
69
        code_length = file.readInt();
70
//        System.out.println("readInt");
71
72
//        System.out.println("+++++++++++++++++"+code_length+"+++++++++++++++++");
73
68
        code = new byte[code_length]; // Read byte code
74
        code = new byte[code_length]; // Read byte code
69
        file.readFully(code);
75
        file.readFully(code);
76
70
        /* Read exception table that contains all regions where an exception
77
        /* Read exception table that contains all regions where an exception
71
         * handler is active, i.e., a try { ... } catch() block.
78
         * handler is active, i.e., a try { ... } catch() block.
72
         */
79
         */
Lines 89-94 public final class Code extends Attribute { Link Here
89
         */
96
         */
90
        this.length = length;
97
        this.length = length;
91
    }
98
    }
99
	
100
	public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
101
            throws IOException {
102
		file.skipBytes(4);
103
		int code_length = file.readInt();
104
		file.skipBytes(code_length);
105
		int exception_table_length = file.readUnsignedShort();
106
        for (int i = 0; i < exception_table_length; i++) {
107
        	file.skipBytes(8);
108
        }
109
        int attributes_count = file.readUnsignedShort();
110
        for (int i = 0; i < attributes_count; i++) {
111
            Attribute.skipAttribute(file, constant_pool);
112
        }
113
	}
92
114
93
115
94
    /**
116
    /**
Lines 103-109 public final class Code extends Attribute { Link Here
103
     */
125
     */
104
    public Code(int name_index, int length, int max_stack, int max_locals, byte[] code,
126
    public Code(int name_index, int length, int max_stack, int max_locals, byte[] code,
105
            CodeException[] exception_table, Attribute[] attributes, ConstantPool constant_pool) {
127
            CodeException[] exception_table, Attribute[] attributes, ConstantPool constant_pool) {
106
        super(Constants.ATTR_CODE, name_index, length, constant_pool);
128
    	super(Constants.ATTR_CODE, name_index, length, constant_pool);
107
        this.max_stack = max_stack;
129
        this.max_stack = max_stack;
108
        this.max_locals = max_locals;
130
        this.max_locals = max_locals;
109
        setCode(code);
131
        setCode(code);
Lines 129-135 public final class Code extends Attribute { Link Here
129
     * @return the internal length of this code attribute (minus the first 6 bytes) 
151
     * @return the internal length of this code attribute (minus the first 6 bytes) 
130
     * and excluding all its attributes
152
     * and excluding all its attributes
131
     */
153
     */
132
    private int getInternalLength() {
154
    private final int getInternalLength() {
133
        return 2 /*max_stack*/+ 2 /*max_locals*/+ 4 /*code length*/
155
        return 2 /*max_stack*/+ 2 /*max_locals*/+ 4 /*code length*/
134
                + code_length /*byte-code*/
156
                + code_length /*byte-code*/
135
                + 2 /*exception-table length*/
157
                + 2 /*exception-table length*/
Lines 142-148 public final class Code extends Attribute { Link Here
142
     * @return the full size of this code attribute, minus its first 6 bytes,
164
     * @return the full size of this code attribute, minus its first 6 bytes,
143
     * including the size of all its contained attributes
165
     * including the size of all its contained attributes
144
     */
166
     */
145
    private int calculateLength() {
167
    private final int calculateLength() {
146
        int len = 0;
168
        int len = 0;
147
        for (int i = 0; i < attributes_count; i++) {
169
        for (int i = 0; i < attributes_count; i++) {
148
            len += attributes[i].length + 6 /*attribute header size*/;
170
            len += attributes[i].length + 6 /*attribute header size*/;
(-)a/java/org/apache/tomcat/util/bcel/classfile/CodeException.java (+1 lines)
Lines 29-34 import org.apache.tomcat.util.bcel.Constants; Link Here
29
 * attribute and is used only there. It contains a range in which a
29
 * attribute and is used only there. It contains a range in which a
30
 * particular exception handler is active.
30
 * particular exception handler is active.
31
 *
31
 *
32
 * @version $Id$
32
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
33
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
33
 * @see     Code
34
 * @see     Code
34
 */
35
 */
(-)a/java/org/apache/tomcat/util/bcel/classfile/Constant.java (-4 / +5 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
import java.io.Serializable;
22
import java.io.Serializable;
23
23
Lines 29-34 import org.apache.tomcat.util.bcel.util.BCELComparator; Link Here
29
 * in the constant pool of a class file. The classes keep closely to
29
 * in the constant pool of a class file. The classes keep closely to
30
 * the JVM specification.
30
 * the JVM specification.
31
 *
31
 *
32
 * @version $Id$
32
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
33
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
33
 */
34
 */
34
public abstract class Constant implements Cloneable, Serializable {
35
public abstract class Constant implements Cloneable, Serializable {
Lines 85-93 public abstract class Constant implements Cloneable, Serializable { Link Here
85
86
86
87
87
    @Override
88
    @Override
88
    public Object clone() {
89
    public Constant clone() {
89
        try {
90
        try {
90
            return super.clone();
91
            return (Constant) super.clone();
91
        } catch (CloneNotSupportedException e) {
92
        } catch (CloneNotSupportedException e) {
92
            throw new Error("Clone Not Supported"); // never happens
93
            throw new Error("Clone Not Supported"); // never happens
93
        }
94
        }
Lines 100-106 public abstract class Constant implements Cloneable, Serializable { Link Here
100
     * @param file Input stream
101
     * @param file Input stream
101
     * @return Constant object
102
     * @return Constant object
102
     */
103
     */
103
    static Constant readConstant( DataInputStream file ) throws IOException,
104
    static final Constant readConstant( DataInput file ) throws IOException,
104
            ClassFormatException {
105
            ClassFormatException {
105
        byte b = file.readByte(); // Read tag byte
106
        byte b = file.readByte(); // Read tag byte
106
        switch (b) {
107
        switch (b) {
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantCP.java (+1 lines)
Lines 23-28 import java.io.IOException; Link Here
23
/** 
23
/** 
24
 * Abstract super class for Fieldref and Methodref constants.
24
 * Abstract super class for Fieldref and Methodref constants.
25
 *
25
 *
26
 * @version $Id$
26
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
27
 * @see     ConstantFieldref
28
 * @see     ConstantFieldref
28
 * @see     ConstantMethodref
29
 * @see     ConstantMethodref
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantClass.java (+1 lines)
Lines 27-32 import org.apache.tomcat.util.bcel.Constants; Link Here
27
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
27
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
28
 * and represents a reference to a (external) class.
28
 * and represents a reference to a (external) class.
29
 *
29
 *
30
 * @version $Id$
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @see     Constant
32
 * @see     Constant
32
 */
33
 */
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantDouble.java (+1 lines)
Lines 27-32 import org.apache.tomcat.util.bcel.Constants; Link Here
27
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
27
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
28
 * and represents a reference to a Double object.
28
 * and represents a reference to a Double object.
29
 *
29
 *
30
 * @version $Id$
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @see     Constant
32
 * @see     Constant
32
 */
33
 */
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantFieldref.java (-2 / +3 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 25-30 import org.apache.tomcat.util.bcel.Constants; Link Here
25
/** 
25
/** 
26
 * This class represents a constant pool reference to a field.
26
 * This class represents a constant pool reference to a field.
27
 *
27
 *
28
 * @version $Id$
28
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29
 */
30
 */
30
public final class ConstantFieldref extends ConstantCP {
31
public final class ConstantFieldref extends ConstantCP {
Lines 38-44 public final class ConstantFieldref extends ConstantCP { Link Here
38
     * @param file input stream
39
     * @param file input stream
39
     * @throws IOException
40
     * @throws IOException
40
     */
41
     */
41
    ConstantFieldref(DataInputStream file) throws IOException {
42
    ConstantFieldref(DataInput file) throws IOException {
42
        super(Constants.CONSTANT_Fieldref, file);
43
        super(Constants.CONSTANT_Fieldref, file);
43
    }
44
    }
44
}
45
}
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantFloat.java (+1 lines)
Lines 27-32 import org.apache.tomcat.util.bcel.Constants; Link Here
27
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
27
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
28
 * and represents a reference to a float object.
28
 * and represents a reference to a float object.
29
 *
29
 *
30
 * @version $Id$
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @see     Constant
32
 * @see     Constant
32
 */
33
 */
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantInteger.java (+1 lines)
Lines 27-32 import org.apache.tomcat.util.bcel.Constants; Link Here
27
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
27
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
28
 * and represents a reference to an int object.
28
 * and represents a reference to an int object.
29
 *
29
 *
30
 * @version $Id$
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @see     Constant
32
 * @see     Constant
32
 */
33
 */
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantInterfaceMethodref.java (-2 / +4 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 25-30 import org.apache.tomcat.util.bcel.Constants; Link Here
25
/** 
25
/** 
26
 * This class represents a constant pool reference to an interface method.
26
 * This class represents a constant pool reference to an interface method.
27
 *
27
 *
28
 * @version $Id$
28
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29
 */
30
 */
30
public final class ConstantInterfaceMethodref extends ConstantCP {
31
public final class ConstantInterfaceMethodref extends ConstantCP {
Lines 38-44 public final class ConstantInterfaceMethodref extends ConstantCP { Link Here
38
     * @param file input stream
39
     * @param file input stream
39
     * @throws IOException
40
     * @throws IOException
40
     */
41
     */
41
    ConstantInterfaceMethodref(DataInputStream file) throws IOException {
42
    ConstantInterfaceMethodref(DataInput file) throws IOException {
42
        super(Constants.CONSTANT_InterfaceMethodref, file);
43
        super(Constants.CONSTANT_InterfaceMethodref, file);
43
    }
44
    }
45
44
}
46
}
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantLong.java (+1 lines)
Lines 27-32 import org.apache.tomcat.util.bcel.Constants; Link Here
27
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
27
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
28
 * and represents a reference to a long object.
28
 * and represents a reference to a long object.
29
 *
29
 *
30
 * @version $Id$
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @see     Constant
32
 * @see     Constant
32
 */
33
 */
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantMethodref.java (-2 / +3 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 25-30 import org.apache.tomcat.util.bcel.Constants; Link Here
25
/** 
25
/** 
26
 * This class represents a constant pool reference to a method.
26
 * This class represents a constant pool reference to a method.
27
 *
27
 *
28
 * @version $Id$
28
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29
 */
30
 */
30
public final class ConstantMethodref extends ConstantCP {
31
public final class ConstantMethodref extends ConstantCP {
Lines 38-44 public final class ConstantMethodref extends ConstantCP { Link Here
38
     * @param file input stream
39
     * @param file input stream
39
     * @throws IOException
40
     * @throws IOException
40
     */
41
     */
41
    ConstantMethodref(DataInputStream file) throws IOException {
42
    ConstantMethodref(DataInput file) throws IOException {
42
        super(Constants.CONSTANT_Methodref, file);
43
        super(Constants.CONSTANT_Methodref, file);
43
    }
44
    }
44
}
45
}
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantNameAndType.java (+1 lines)
Lines 28-33 import org.apache.tomcat.util.bcel.Constants; Link Here
28
 * and represents a reference to the name and signature
28
 * and represents a reference to the name and signature
29
 * of a field or method.
29
 * of a field or method.
30
 *
30
 *
31
 * @version $Id$
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32
 * @see     Constant
33
 * @see     Constant
33
 */
34
 */
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantPool.java (-3 / +4 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
import java.io.Serializable;
22
import java.io.Serializable;
23
23
Lines 31-36 import org.apache.tomcat.util.bcel.Constants; Link Here
31
 * programatically should see <a href="../generic/ConstantPoolGen.html">
31
 * programatically should see <a href="../generic/ConstantPoolGen.html">
32
 * ConstantPoolGen</a>.
32
 * ConstantPoolGen</a>.
33
33
34
 * @version $Id$
34
 * @see     Constant
35
 * @see     Constant
35
 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
36
 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
36
 */
37
 */
Lines 48-54 public class ConstantPool implements Cloneable, Serializable { Link Here
48
     * @throws IOException
49
     * @throws IOException
49
     * @throws ClassFormatException
50
     * @throws ClassFormatException
50
     */
51
     */
51
    ConstantPool(DataInputStream file) throws IOException, ClassFormatException {
52
    ConstantPool(DataInput file) throws IOException, ClassFormatException {
52
        byte tag;
53
        byte tag;
53
        constant_pool_count = file.readUnsignedShort();
54
        constant_pool_count = file.readUnsignedShort();
54
        constant_pool = new Constant[constant_pool_count];
55
        constant_pool = new Constant[constant_pool_count];
Lines 128-134 public class ConstantPool implements Cloneable, Serializable { Link Here
128
    }
129
    }
129
130
130
131
131
    private static String escape( String str ) {
132
    private static final String escape( String str ) {
132
        int len = str.length();
133
        int len = str.length();
133
        StringBuilder buf = new StringBuilder(len + 5);
134
        StringBuilder buf = new StringBuilder(len + 5);
134
        char[] ch = str.toCharArray();
135
        char[] ch = str.toCharArray();
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantString.java (+1 lines)
Lines 27-32 import org.apache.tomcat.util.bcel.Constants; Link Here
27
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
27
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
28
 * and represents a reference to a String object.
28
 * and represents a reference to a String object.
29
 *
29
 *
30
 * @version $Id$
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @see     Constant
32
 * @see     Constant
32
 */
33
 */
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java (-2 / +2 lines)
Lines 17-23 Link Here
17
package org.apache.tomcat.util.bcel.classfile;
17
package org.apache.tomcat.util.bcel.classfile;
18
18
19
import java.io.DataInput;
19
import java.io.DataInput;
20
import java.io.DataInputStream;
21
import java.io.IOException;
20
import java.io.IOException;
22
import java.util.HashMap;
21
import java.util.HashMap;
23
import java.util.LinkedHashMap;
22
import java.util.LinkedHashMap;
Lines 30-35 import org.apache.tomcat.util.bcel.Constants; Link Here
30
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
29
 * <A HREF="org.apache.tomcat.util.bcel.classfile.Constant.html">Constant</A> class 
31
 * and represents a reference to a Utf8 encoded string.
30
 * and represents a reference to a Utf8 encoded string.
32
 *
31
 *
32
 * @version $Id$
33
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
33
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
34
 * @see     Constant
34
 * @see     Constant
35
 */
35
 */
Lines 69-75 public final class ConstantUtf8 extends Constant { Link Here
69
        return getCachedInstance(s);
69
        return getCachedInstance(s);
70
    }
70
    }
71
71
72
    static ConstantUtf8 getInstance(DataInputStream file) throws IOException {
72
    static ConstantUtf8 getInstance(DataInput file) throws IOException {
73
        return getInstance(file.readUTF());
73
        return getInstance(file.readUTF());
74
    }
74
    }
75
75
(-)a/java/org/apache/tomcat/util/bcel/classfile/ConstantValue.java (+6 lines)
Lines 26-31 import org.apache.tomcat.util.bcel.Constants; Link Here
26
 * value, i.e., a default value for initializing a class field.
26
 * value, i.e., a default value for initializing a class field.
27
 * This class is instantiated by the <em>Attribute.readAttribute()</em> method.
27
 * This class is instantiated by the <em>Attribute.readAttribute()</em> method.
28
 *
28
 *
29
 * @version $Id$
29
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30
 * @see     Attribute
31
 * @see     Attribute
31
 */
32
 */
Lines 47-52 public final class ConstantValue extends Attribute { Link Here
47
            throws IOException {
48
            throws IOException {
48
        this(name_index, length, file.readUnsignedShort(), constant_pool);
49
        this(name_index, length, file.readUnsignedShort(), constant_pool);
49
    }
50
    }
51
    // could the process of "constant_pool" can be skip?????????????????????????????
52
    public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
53
    		throws IOException {
54
    	file.skipBytes(2);
55
    }
50
56
51
57
52
    /**
58
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/Deprecated.java (-2 / +11 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 27-32 import org.apache.tomcat.util.bcel.Constants; Link Here
27
 * deprecated method.
27
 * deprecated method.
28
 * It is instantiated from the <em>Attribute.readAttribute()</em> method.
28
 * It is instantiated from the <em>Attribute.readAttribute()</em> method.
29
 *
29
 *
30
 * @version $Id$
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @see     Attribute
32
 * @see     Attribute
32
 */
33
 */
Lines 56-62 public final class Deprecated extends Attribute { Link Here
56
     * @param constant_pool Array of constants
57
     * @param constant_pool Array of constants
57
     * @throws IOException
58
     * @throws IOException
58
     */
59
     */
59
    Deprecated(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
60
    Deprecated(int name_index, int length, DataInput file, ConstantPool constant_pool)
60
            throws IOException {
61
            throws IOException {
61
        this(name_index, length, (byte[]) null, constant_pool);
62
        this(name_index, length, (byte[]) null, constant_pool);
62
        if (length > 0) {
63
        if (length > 0) {
Lines 65-70 public final class Deprecated extends Attribute { Link Here
65
            System.err.println("Deprecated attribute with length > 0");
66
            System.err.println("Deprecated attribute with length > 0");
66
        }
67
        }
67
    }
68
    }
69
    
70
    public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
71
            throws IOException {
72
    	if(length > 0) {
73
    		file.skipBytes(length);
74
            System.err.println("Deprecated attribute with length > 0");
75
    	}
76
    }
68
77
69
78
70
    /**
79
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/ElementValue.java (-5 / +90 lines)
Lines 17-29 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.DataOutputStream;
21
import java.io.DataOutput;
22
import java.io.IOException;
22
import java.io.IOException;
23
23
24
/**
24
/**
25
 * @version $Id: ElementValue
25
 * @author <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
26
 * @author <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
26
 * @since 6.0
27
 * @since 5.3
27
 */
28
 */
28
public abstract class ElementValue
29
public abstract class ElementValue
29
{
30
{
Lines 46-52 public abstract class ElementValue Link Here
46
47
47
    public abstract String stringifyValue();
48
    public abstract String stringifyValue();
48
49
49
    public abstract void dump(DataOutputStream dos) throws IOException;
50
    public abstract void dump(DataOutput dos) throws IOException;
50
51
51
    public static final int STRING = 's';
52
    public static final int STRING = 's';
52
53
Lines 74-80 public abstract class ElementValue Link Here
74
75
75
    public static final int PRIMITIVE_BOOLEAN = 'Z';
76
    public static final int PRIMITIVE_BOOLEAN = 'Z';
76
77
77
    public static ElementValue readElementValue(DataInputStream dis,
78
    public static ElementValue readElementValue(DataInput dis,
78
            ConstantPool cpool) throws IOException
79
            ConstantPool cpool) throws IOException
79
    {
80
    {
80
        byte type = dis.readByte();
81
        byte type = dis.readByte();
Lines 129-132 public abstract class ElementValue Link Here
129
                    "Unexpected element value kind in annotation: " + type);
130
                    "Unexpected element value kind in annotation: " + type);
130
        }
131
        }
131
    }
132
    }
133
    public static void skipElementValue(DataInput dis,
134
            ConstantPool cpool) throws IOException
135
    {
136
    	byte type = dis.readByte();
137
        switch (type)
138
        {
139
        case 'B': // byte
140
//            return new SimpleElementValue(PRIMITIVE_BYTE, dis
141
//                    .readUnsignedShort(), cpool);
142
            dis.skipBytes(2);
143
            return;
144
        case 'C': // char
145
//            return new SimpleElementValue(PRIMITIVE_CHAR, dis
146
//                    .readUnsignedShort(), cpool);
147
        	dis.skipBytes(2);
148
        	return;
149
        case 'D': // double
150
//            return new SimpleElementValue(PRIMITIVE_DOUBLE, dis
151
//                    .readUnsignedShort(), cpool);
152
        	dis.skipBytes(2);
153
        	return;
154
        case 'F': // float
155
//            return new SimpleElementValue(PRIMITIVE_FLOAT, dis
156
//                    .readUnsignedShort(), cpool);
157
            dis.skipBytes(2);
158
            return;
159
        case 'I': // int
160
//            return new SimpleElementValue(PRIMITIVE_INT, dis
161
//                    .readUnsignedShort(), cpool);
162
            dis.skipBytes(2);
163
            return;
164
        case 'J': // long
165
//            return new SimpleElementValue(PRIMITIVE_LONG, dis
166
//                    .readUnsignedShort(), cpool);
167
        	dis.skipBytes(2);
168
        	return;
169
        case 'S': // short
170
//            return new SimpleElementValue(PRIMITIVE_SHORT, dis
171
//                    .readUnsignedShort(), cpool);
172
            dis.skipBytes(2);
173
            return;
174
        case 'Z': // boolean
175
//            return new SimpleElementValue(PRIMITIVE_BOOLEAN, dis
176
//                    .readUnsignedShort(), cpool);
177
            dis.skipBytes(2);
178
            return;
179
        case 's': // String
180
//            return new SimpleElementValue(STRING, dis.readUnsignedShort(),
181
//                    cpool);
182
        	dis.skipBytes(2);
183
        	return;
184
        case 'e': // Enum constant
185
//            return new EnumElementValue(ENUM_CONSTANT, dis.readUnsignedShort(),
186
//                    dis.readUnsignedShort(), cpool);
187
        	dis.skipBytes(4);
188
        	return;
189
        case 'c': // Class
190
//            return new ClassElementValue(CLASS, dis.readUnsignedShort(), cpool);
191
            dis.skipBytes(2);
192
            return;
193
        case '@': // Annotation
194
            // TODO isRuntimeVisible
195
//            return new AnnotationElementValue(ANNOTATION, AnnotationEntry.read(
196
//                    dis, cpool), cpool);
197
        	AnnotationEntry.skip(dis, cpool);
198
        	return;
199
        case '[': // Array
200
//            int numArrayVals = dis.readUnsignedShort();
201
//            ElementValue[] evalues = new ElementValue[numArrayVals];
202
//            for (int j = 0; j < numArrayVals; j++)
203
//            {
204
//                evalues[j] = ElementValue.readElementValue(dis, cpool);
205
//            }
206
//            return new ArrayElementValue(ARRAY, evalues, cpool);
207
            int numArrayVals = dis.readUnsignedShort();
208
            for (int j = 0; j < numArrayVals; j++){
209
                ElementValue.skipElementValue(dis, cpool);
210
            }
211
            return;
212
        default:
213
            throw new RuntimeException(
214
                    "Unexpected element value kind in annotation: " + type);
215
        }
216
    }
132
}
217
}
(-)a/java/org/apache/tomcat/util/bcel/classfile/ElementValuePair.java (-3 / +4 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataOutputStream;
20
import java.io.DataOutput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 25-32 import org.apache.tomcat.util.bcel.Constants; Link Here
25
/**
25
/**
26
 * an annotation's element value pair
26
 * an annotation's element value pair
27
 * 
27
 * 
28
 * @version $Id: ElementValuePair
28
 * @author <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
29
 * @author <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
29
 * @since 6.0
30
 * @since 5.3
30
 */
31
 */
31
public class ElementValuePair
32
public class ElementValuePair
32
{
33
{
Lines 56-62 public class ElementValuePair Link Here
56
        return elementValue;
57
        return elementValue;
57
    }
58
    }
58
    
59
    
59
    protected void dump(DataOutputStream dos) throws IOException {
60
    protected void dump(DataOutput dos) throws IOException {
60
        dos.writeShort(elementNameIndex); // u2 name of the element
61
        dos.writeShort(elementNameIndex); // u2 name of the element
61
        elementValue.dump(dos);
62
        elementValue.dump(dos);
62
    }
63
    }
(-)a/java/org/apache/tomcat/util/bcel/classfile/EnclosingMethod.java (-2 / +7 lines)
Lines 16-22 Link Here
16
 */
16
 */
17
package org.apache.tomcat.util.bcel.classfile;
17
package org.apache.tomcat.util.bcel.classfile;
18
18
19
import java.io.DataInputStream;
19
import java.io.DataInput;
20
import java.io.IOException;
20
import java.io.IOException;
21
21
22
import org.apache.tomcat.util.bcel.Constants;
22
import org.apache.tomcat.util.bcel.Constants;
Lines 30-36 public class EnclosingMethod extends Attribute { Link Here
30
    private static final long serialVersionUID = 6755214228300933233L;
30
    private static final long serialVersionUID = 6755214228300933233L;
31
31
32
    // Ctors - and code to read an attribute in.
32
    // Ctors - and code to read an attribute in.
33
    public EnclosingMethod(int nameIndex, int len, DataInputStream dis,
33
    public EnclosingMethod(int nameIndex, int len, DataInput dis,
34
            ConstantPool cpool) throws IOException {
34
            ConstantPool cpool) throws IOException {
35
        super(Constants.ATTR_ENCLOSING_METHOD, nameIndex, len, cpool);
35
        super(Constants.ATTR_ENCLOSING_METHOD, nameIndex, len, cpool);
36
        // Unused class index
36
        // Unused class index
Lines 38-43 public class EnclosingMethod extends Attribute { Link Here
38
        // Unused method index
38
        // Unused method index
39
        dis.readUnsignedShort();
39
        dis.readUnsignedShort();
40
    }
40
    }
41
    
42
    public static void skip(int nameIndex, int len, DataInput dis,
43
            ConstantPool cpool) throws IOException {
44
    	dis.skipBytes(4);
45
    }
41
46
42
    @Override
47
    @Override
43
    public Attribute copy(ConstantPool constant_pool) {
48
    public Attribute copy(ConstantPool constant_pool) {
(-)a/java/org/apache/tomcat/util/bcel/classfile/EnumElementValue.java (-2 / +2 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataOutputStream;
20
import java.io.DataOutput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 41-47 public class EnumElementValue extends ElementValue Link Here
41
    }
41
    }
42
42
43
    @Override
43
    @Override
44
    public void dump(DataOutputStream dos) throws IOException
44
    public void dump(DataOutput dos) throws IOException
45
    {
45
    {
46
        dos.writeByte(type); // u1 type of value (ENUM_CONSTANT == 'e')
46
        dos.writeByte(type); // u1 type of value (ENUM_CONSTANT == 'e')
47
        dos.writeShort(typeIdx); // u2
47
        dos.writeShort(typeIdx); // u2
(-)a/java/org/apache/tomcat/util/bcel/classfile/ExceptionTable.java (-2 / +11 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 30-35 import org.apache.tomcat.util.bcel.Constants; Link Here
30
 * attribute using the name <em>Exceptions</em> (which is inconsistent
30
 * attribute using the name <em>Exceptions</em> (which is inconsistent
31
 * with the other classes).
31
 * with the other classes).
32
 *
32
 *
33
 * @version $Id$
33
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
34
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
34
 * @see     Code
35
 * @see     Code
35
 */
36
 */
Lines 61-67 public final class ExceptionTable extends Attribute { Link Here
61
     * @param constant_pool Array of constants
62
     * @param constant_pool Array of constants
62
     * @throws IOException
63
     * @throws IOException
63
     */
64
     */
64
    ExceptionTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
65
    ExceptionTable(int name_index, int length, DataInput file, ConstantPool constant_pool)
65
            throws IOException {
66
            throws IOException {
66
        this(name_index, length, (int[]) null, constant_pool);
67
        this(name_index, length, (int[]) null, constant_pool);
67
        number_of_exceptions = file.readUnsignedShort();
68
        number_of_exceptions = file.readUnsignedShort();
Lines 70-75 public final class ExceptionTable extends Attribute { Link Here
70
            exception_index_table[i] = file.readUnsignedShort();
71
            exception_index_table[i] = file.readUnsignedShort();
71
        }
72
        }
72
    }
73
    }
74
    
75
    public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
76
            throws IOException {
77
        int number_of_exceptions = file.readUnsignedShort();
78
        for (int i = 0; i < number_of_exceptions; i++) {
79
        	file.skipBytes(2);
80
        }
81
    }
73
82
74
83
75
    /**
84
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/Field.java (-2 / +7 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 27-32 import org.apache.tomcat.util.bcel.util.BCELComparator; Link Here
27
 * This class represents the field info structure, i.e., the representation 
27
 * This class represents the field info structure, i.e., the representation 
28
 * for a variable in the class. See JVM specification for details.
28
 * for a variable in the class. See JVM specification for details.
29
 *
29
 *
30
 * @version $Id$
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 */
32
 */
32
public final class Field extends FieldOrMethod {
33
public final class Field extends FieldOrMethod {
Lines 55-64 public final class Field extends FieldOrMethod { Link Here
55
     * Construct object from file stream.
56
     * Construct object from file stream.
56
     * @param file Input stream
57
     * @param file Input stream
57
     */
58
     */
58
    Field(DataInputStream file, ConstantPool constant_pool) throws IOException,
59
    Field(DataInput file, ConstantPool constant_pool) throws IOException,
59
            ClassFormatException {
60
            ClassFormatException {
60
        super(file, constant_pool);
61
        super(file, constant_pool);
61
    }
62
    }
63
    
64
    public static void skip(DataInput file, ConstantPool constant_pool) throws ClassFormatException, IOException{
65
    	FieldOrMethod.skip(file, constant_pool);
66
    }
62
67
63
68
64
    /**
69
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/FieldOrMethod.java (-2 / +13 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 25-30 import org.apache.tomcat.util.bcel.Constants; Link Here
25
/** 
25
/** 
26
 * Abstract super class for fields and methods.
26
 * Abstract super class for fields and methods.
27
 *
27
 *
28
 * @version $Id$
28
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29
 */
30
 */
30
public abstract class FieldOrMethod extends AccessFlags implements Cloneable {
31
public abstract class FieldOrMethod extends AccessFlags implements Cloneable {
Lines 47-53 public abstract class FieldOrMethod extends AccessFlags implements Cloneable { Link Here
47
     * @throws IOException
48
     * @throws IOException
48
     * @throws ClassFormatException
49
     * @throws ClassFormatException
49
     */
50
     */
50
    protected FieldOrMethod(DataInputStream file, ConstantPool constant_pool) throws IOException,
51
    protected FieldOrMethod(DataInput file, ConstantPool constant_pool) throws IOException,
51
            ClassFormatException {
52
            ClassFormatException {
52
        this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), null,
53
        this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), null,
53
                constant_pool);
54
                constant_pool);
Lines 57-62 public abstract class FieldOrMethod extends AccessFlags implements Cloneable { Link Here
57
            attributes[i] = Attribute.readAttribute(file, constant_pool);
58
            attributes[i] = Attribute.readAttribute(file, constant_pool);
58
        }
59
        }
59
    }
60
    }
61
    
62
    public static void skip(DataInput file, ConstantPool constant_pool) throws IOException,
63
            ClassFormatException {
64
    	file.skipBytes(6);
65
    	int attributes_count = file.readUnsignedShort();
66
    	for (int j = 0; j < attributes_count; j++) {
67
        	Attribute.skipAttribute(file, constant_pool);
68
        }
69
    	
70
    }
60
71
61
72
62
    /**
73
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/InnerClass.java (+5 lines)
Lines 29-34 import org.apache.tomcat.util.bcel.Constants; Link Here
29
 * indices of the inner and outer classes, the name and the attributes
29
 * indices of the inner and outer classes, the name and the attributes
30
 * of the inner class.
30
 * of the inner class.
31
 *
31
 *
32
 * @version $Id$
32
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
33
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
33
 * @see InnerClasses
34
 * @see InnerClasses
34
 */
35
 */
Lines 50-55 public final class InnerClass implements Cloneable, Serializable { Link Here
50
        this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file
51
        this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file
51
                .readUnsignedShort());
52
                .readUnsignedShort());
52
    }
53
    }
54
    
55
    public static void skip(DataInput file) throws IOException {
56
    	file.skipBytes(8);
57
    }
53
58
54
59
55
    /**
60
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/InnerClasses.java (-2 / +11 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 28-33 import org.apache.tomcat.util.bcel.Constants; Link Here
28
 * to the source file of this class.
28
 * to the source file of this class.
29
 * It is instantiated from the <em>Attribute.readAttribute()</em> method.
29
 * It is instantiated from the <em>Attribute.readAttribute()</em> method.
30
 *
30
 *
31
 * @version $Id$
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32
 * @see     Attribute
33
 * @see     Attribute
33
 */
34
 */
Lines 60-66 public final class InnerClasses extends Attribute { Link Here
60
     * @param constant_pool Array of constants
61
     * @param constant_pool Array of constants
61
     * @throws IOException
62
     * @throws IOException
62
     */
63
     */
63
    InnerClasses(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
64
    InnerClasses(int name_index, int length, DataInput file, ConstantPool constant_pool)
64
            throws IOException {
65
            throws IOException {
65
        this(name_index, length, (InnerClass[]) null, constant_pool);
66
        this(name_index, length, (InnerClass[]) null, constant_pool);
66
        number_of_classes = file.readUnsignedShort();
67
        number_of_classes = file.readUnsignedShort();
Lines 69-74 public final class InnerClasses extends Attribute { Link Here
69
            inner_classes[i] = new InnerClass(file);
70
            inner_classes[i] = new InnerClass(file);
70
        }
71
        }
71
    }
72
    }
73
    
74
    public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
75
            throws IOException {
76
        int number_of_classes = file.readUnsignedShort();
77
        for (int i = 0; i < number_of_classes; i++) {
78
        	InnerClass.skip(file);
79
        }
80
    }
72
81
73
82
74
    /**
83
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/JavaClass.java (-1 / +3 lines)
Lines 32-37 import org.apache.tomcat.util.bcel.util.BCELComparator; Link Here
32
 * class file.  Those interested in programatically generating classes
32
 * class file.  Those interested in programatically generating classes
33
 * should see the <a href="../generic/ClassGen.html">ClassGen</a> class.
33
 * should see the <a href="../generic/ClassGen.html">ClassGen</a> class.
34
34
35
 * @version $Id$
35
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
36
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
36
 */
37
 */
37
public class JavaClass extends AccessFlags
38
public class JavaClass extends AccessFlags
Lines 156-162 public class JavaClass extends AccessFlags Link Here
156
            // Find attributes that contain annotation data
157
            // Find attributes that contain annotation data
157
            Attribute[] attrs = getAttributes();
158
            Attribute[] attrs = getAttributes();
158
            List<AnnotationEntry> accumulatedAnnotations = new ArrayList<AnnotationEntry>();
159
            List<AnnotationEntry> accumulatedAnnotations = new ArrayList<AnnotationEntry>();
159
            for (Attribute attribute : attrs) {
160
            for (int i = 0; i < attrs.length; i++) {
161
                Attribute attribute = attrs[i];
160
                if (attribute instanceof Annotations) {
162
                if (attribute instanceof Annotations) {
161
                    Annotations runtimeAnnotations = (Annotations)attribute;
163
                    Annotations runtimeAnnotations = (Annotations)attribute;
162
                    for(int j = 0; j < runtimeAnnotations.getAnnotationEntries().length; j++)
164
                    for(int j = 0; j < runtimeAnnotations.getAnnotationEntries().length; j++)
(-)a/java/org/apache/tomcat/util/bcel/classfile/LineNumber.java (+5 lines)
Lines 27-32 import java.io.Serializable; Link Here
27
 * the source that corresponds to a relative address in the byte code. This
27
 * the source that corresponds to a relative address in the byte code. This
28
 * is used for debugging purposes.
28
 * is used for debugging purposes.
29
 *
29
 *
30
 * @version $Id$
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @see     LineNumberTable
32
 * @see     LineNumberTable
32
 */
33
 */
Lines 45-50 public final class LineNumber implements Cloneable, Serializable { Link Here
45
    LineNumber(DataInput file) throws IOException {
46
    LineNumber(DataInput file) throws IOException {
46
        this(file.readUnsignedShort(), file.readUnsignedShort());
47
        this(file.readUnsignedShort(), file.readUnsignedShort());
47
    }
48
    }
49
    
50
    public static void skip(DataInput file) throws IOException{
51
    	file.skipBytes(4);
52
    }
48
53
49
54
50
    /**
55
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/LineNumberTable.java (-2 / +12 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 27-32 import org.apache.tomcat.util.bcel.Constants; Link Here
27
 * purposes. This attribute is used by the <em>Code</em> attribute. It
27
 * purposes. This attribute is used by the <em>Code</em> attribute. It
28
 * contains pairs of PCs and line numbers.
28
 * contains pairs of PCs and line numbers.
29
 *
29
 *
30
 * @version $Id$
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @see     Code
32
 * @see     Code
32
 * @see LineNumber
33
 * @see LineNumber
Lines 59-65 public final class LineNumberTable extends Attribute { Link Here
59
     * @param constant_pool Array of constants
60
     * @param constant_pool Array of constants
60
     * @throws IOException
61
     * @throws IOException
61
     */
62
     */
62
    LineNumberTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
63
    LineNumberTable(int name_index, int length, DataInput file, ConstantPool constant_pool)
63
            throws IOException {
64
            throws IOException {
64
        this(name_index, length, (LineNumber[]) null, constant_pool);
65
        this(name_index, length, (LineNumber[]) null, constant_pool);
65
        line_number_table_length = (file.readUnsignedShort());
66
        line_number_table_length = (file.readUnsignedShort());
Lines 68-73 public final class LineNumberTable extends Attribute { Link Here
68
            line_number_table[i] = new LineNumber(file);
69
            line_number_table[i] = new LineNumber(file);
69
        }
70
        }
70
    }
71
    }
72
    
73
    public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
74
            throws IOException {
75
    	int line_number_table_length = (file.readUnsignedShort());
76
        for (int i = 0; i < line_number_table_length; i++) {
77
        	LineNumber.skip(file);
78
        }
79
80
    }
71
81
72
82
73
    /**
83
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/LocalVariable.java (+5 lines)
Lines 28-33 import org.apache.tomcat.util.bcel.Constants; Link Here
28
 * This class represents a local variable within a method. It contains its
28
 * This class represents a local variable within a method. It contains its
29
 * scope, name, signature and index on the method's frame.
29
 * scope, name, signature and index on the method's frame.
30
 *
30
 *
31
 * @version $Id$
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32
 * @see     LocalVariableTable
33
 * @see     LocalVariableTable
33
 */
34
 */
Lines 53-58 public final class LocalVariable implements Constants, Cloneable, Serializable { Link Here
53
        this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file
54
        this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file
54
                .readUnsignedShort(), file.readUnsignedShort(), constant_pool);
55
                .readUnsignedShort(), file.readUnsignedShort(), constant_pool);
55
    }
56
    }
57
    
58
    public static void skip(DataInput file, ConstantPool constant_pool) throws IOException {
59
    	file.skipBytes(10);
60
    }
56
61
57
62
58
    /**
63
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/LocalVariableTable.java (-2 / +11 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 26-31 import org.apache.tomcat.util.bcel.Constants; Link Here
26
 * This class represents colection of local variables in a
26
 * This class represents colection of local variables in a
27
 * method. This attribute is contained in the <em>Code</em> attribute.
27
 * method. This attribute is contained in the <em>Code</em> attribute.
28
 *
28
 *
29
 * @version $Id$
29
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30
 * @see     Code
31
 * @see     Code
31
 * @see LocalVariable
32
 * @see LocalVariable
Lines 58-64 public class LocalVariableTable extends Attribute { Link Here
58
     * @param constant_pool Array of constants
59
     * @param constant_pool Array of constants
59
     * @throws IOException
60
     * @throws IOException
60
     */
61
     */
61
    LocalVariableTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
62
    LocalVariableTable(int name_index, int length, DataInput file, ConstantPool constant_pool)
62
            throws IOException {
63
            throws IOException {
63
        this(name_index, length, (LocalVariable[]) null, constant_pool);
64
        this(name_index, length, (LocalVariable[]) null, constant_pool);
64
        local_variable_table_length = (file.readUnsignedShort());
65
        local_variable_table_length = (file.readUnsignedShort());
Lines 67-72 public class LocalVariableTable extends Attribute { Link Here
67
            local_variable_table[i] = new LocalVariable(file, constant_pool);
68
            local_variable_table[i] = new LocalVariable(file, constant_pool);
68
        }
69
        }
69
    }
70
    }
71
    
72
    public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
73
            throws IOException {
74
        int local_variable_table_length = (file.readUnsignedShort());
75
        for (int i = 0; i < local_variable_table_length; i++) {
76
        	LocalVariable.skip(file, constant_pool);
77
        }
78
    }
70
79
71
80
72
    /**
81
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/LocalVariableTypeTable.java (-2 / +11 lines)
Lines 16-22 Link Here
16
 */
16
 */
17
package org.apache.tomcat.util.bcel.classfile;
17
package org.apache.tomcat.util.bcel.classfile;
18
18
19
import java.io.DataInputStream;
19
import java.io.DataInput;
20
import java.io.IOException;
20
import java.io.IOException;
21
21
22
import org.apache.tomcat.util.bcel.Constants;
22
import org.apache.tomcat.util.bcel.Constants;
Lines 61-67 private int local_variable_type_table_length; // Table of local Link Here
61
    setLocalVariableTable(local_variable_table);
61
    setLocalVariableTable(local_variable_table);
62
  }    
62
  }    
63
63
64
  LocalVariableTypeTable(int nameIdx, int len, DataInputStream dis,ConstantPool cpool) throws IOException {
64
  LocalVariableTypeTable(int nameIdx, int len, DataInput dis,ConstantPool cpool) throws IOException {
65
    this(nameIdx, len, (LocalVariable[])null, cpool);
65
    this(nameIdx, len, (LocalVariable[])null, cpool);
66
66
67
    local_variable_type_table_length = (dis.readUnsignedShort());
67
    local_variable_type_table_length = (dis.readUnsignedShort());
Lines 70-75 private int local_variable_type_table_length; // Table of local Link Here
70
    for(int i=0; i < local_variable_type_table_length; i++)
70
    for(int i=0; i < local_variable_type_table_length; i++)
71
      local_variable_type_table[i] = new LocalVariable(dis, cpool);
71
      local_variable_type_table[i] = new LocalVariable(dis, cpool);
72
  }
72
  }
73
  
74
  public static void skip(int nameIdx, int len, DataInput dis,ConstantPool cpool) throws IOException {
75
	  int local_variable_type_table_length = (dis.readUnsignedShort());
76
	  for(int i=0; i < local_variable_type_table_length; i++){
77
		  LocalVariable.skip(dis, cpool);
78
	  }
79
80
81
  }
73
82
74
  public final void setLocalVariableTable(LocalVariable[] local_variable_table)
83
  public final void setLocalVariableTable(LocalVariable[] local_variable_table)
75
  {
84
  {
(-)a/java/org/apache/tomcat/util/bcel/classfile/Method.java (-2 / +8 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 28-33 import org.apache.tomcat.util.bcel.util.BCELComparator; Link Here
28
 * for a method in the class. See JVM specification for details.
28
 * for a method in the class. See JVM specification for details.
29
 * A method has access flags, a name, a signature and a number of attributes.
29
 * A method has access flags, a name, a signature and a number of attributes.
30
 *
30
 *
31
 * @version $Id$
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32
 */
33
 */
33
public final class Method extends FieldOrMethod {
34
public final class Method extends FieldOrMethod {
Lines 66-75 public final class Method extends FieldOrMethod { Link Here
66
     * @throws IOException
67
     * @throws IOException
67
     * @throws ClassFormatException
68
     * @throws ClassFormatException
68
     */
69
     */
69
    Method(DataInputStream file, ConstantPool constant_pool) throws IOException,
70
    Method(DataInput file, ConstantPool constant_pool) throws IOException,
70
            ClassFormatException {
71
            ClassFormatException {
71
        super(file, constant_pool);
72
        super(file, constant_pool);
72
    }
73
    }
74
    
75
    public static void skip(DataInput file, ConstantPool constant_pool) throws IOException,
76
    ClassFormatException {
77
    	FieldOrMethod.skip(file, constant_pool);
78
    }
73
79
74
80
75
    /**
81
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/PMGClass.java (+6 lines)
Lines 26-31 import org.apache.tomcat.util.bcel.Constants; Link Here
26
 * This class is derived from <em>Attribute</em> and represents a reference
26
 * This class is derived from <em>Attribute</em> and represents a reference
27
 * to a PMG attribute.
27
 * to a PMG attribute.
28
 *
28
 *
29
 * @version $Id$
29
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30
 * @see     Attribute
31
 * @see     Attribute
31
 */
32
 */
Lines 47-52 public final class PMGClass extends Attribute { Link Here
47
            throws IOException {
48
            throws IOException {
48
        this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), constant_pool);
49
        this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), constant_pool);
49
    }
50
    }
51
    
52
    public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
53
            throws IOException {
54
    	file.skipBytes(4);
55
    }
50
56
51
57
52
    /**
58
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotationEntry.java (-3 / +10 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 25-32 import org.apache.tomcat.util.bcel.Constants; Link Here
25
/**
25
/**
26
 * represents one parameter annotation in the parameter annotation table
26
 * represents one parameter annotation in the parameter annotation table
27
 * 
27
 * 
28
 * @version $Id: ParameterAnnotationEntry
28
 * @author  <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
29
 * @author  <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
29
 * @since 6.0
30
 * @since 5.3
30
 */
31
 */
31
public class ParameterAnnotationEntry implements Constants {
32
public class ParameterAnnotationEntry implements Constants {
32
33
Lines 39-45 public class ParameterAnnotationEntry implements Constants { Link Here
39
     * @param file Input stream
40
     * @param file Input stream
40
     * @throws IOException
41
     * @throws IOException
41
     */
42
     */
42
    ParameterAnnotationEntry(DataInputStream file, ConstantPool constant_pool) throws IOException {
43
    ParameterAnnotationEntry(DataInput file, ConstantPool constant_pool) throws IOException {
43
        annotation_table_length = (file.readUnsignedShort());
44
        annotation_table_length = (file.readUnsignedShort());
44
        annotation_table = new AnnotationEntry[annotation_table_length];
45
        annotation_table = new AnnotationEntry[annotation_table_length];
45
        for (int i = 0; i < annotation_table_length; i++) {
46
        for (int i = 0; i < annotation_table_length; i++) {
Lines 47-50 public class ParameterAnnotationEntry implements Constants { Link Here
47
        }
48
        }
48
    }
49
    }
49
    
50
    
51
    public static void skip(DataInput file, ConstantPool constant_pool) throws IOException {
52
        int annotation_table_length = (file.readUnsignedShort());
53
        for (int i = 0; i < annotation_table_length; i++) {
54
        	AnnotationEntry.skip(file, constant_pool);
55
        }
56
    }
50
}
57
}
(-)a/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotations.java (-3 / +12 lines)
Lines 17-30 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
/**
23
/**
24
 * base class for parameter annotations
24
 * base class for parameter annotations
25
 * 
25
 * 
26
 * @version $Id: ParameterAnnotations
26
 * @author  <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
27
 * @author  <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
27
 * @since 6.0
28
 * @since 5.3
28
 */
29
 */
29
public abstract class ParameterAnnotations extends Attribute {
30
public abstract class ParameterAnnotations extends Attribute {
30
31
Lines 41-47 public abstract class ParameterAnnotations extends Attribute { Link Here
41
     * @param constant_pool Array of constants
42
     * @param constant_pool Array of constants
42
     */
43
     */
43
    ParameterAnnotations(byte parameter_annotation_type, int name_index, int length,
44
    ParameterAnnotations(byte parameter_annotation_type, int name_index, int length,
44
            DataInputStream file, ConstantPool constant_pool) throws IOException {
45
            DataInput file, ConstantPool constant_pool) throws IOException {
45
        this(parameter_annotation_type, name_index, length, (ParameterAnnotationEntry[]) null,
46
        this(parameter_annotation_type, name_index, length, (ParameterAnnotationEntry[]) null,
46
                constant_pool);
47
                constant_pool);
47
        num_parameters = (file.readUnsignedByte());
48
        num_parameters = (file.readUnsignedByte());
Lines 50-55 public abstract class ParameterAnnotations extends Attribute { Link Here
50
            parameter_annotation_table[i] = new ParameterAnnotationEntry(file, constant_pool);
51
            parameter_annotation_table[i] = new ParameterAnnotationEntry(file, constant_pool);
51
        }
52
        }
52
    }
53
    }
54
    
55
    public static void skip(byte parameter_annotation_type, int name_index, int length,
56
            DataInput file, ConstantPool constant_pool) throws IOException {
57
        int num_parameters = (file.readUnsignedByte());
58
        for (int i = 0; i < num_parameters; i++) {
59
        	ParameterAnnotationEntry.skip(file, constant_pool);
60
        }
61
    }
53
62
54
63
55
    /**
64
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/RuntimeInvisibleAnnotations.java (-4 / +13 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 26-33 import org.apache.tomcat.util.bcel.Constants; Link Here
26
 * represents an annotation that is represented in the class file but is not
26
 * represents an annotation that is represented in the class file but is not
27
 * provided to the JVM.
27
 * provided to the JVM.
28
 * 
28
 * 
29
 * @version $Id: RuntimeInvisibleAnnotations
29
 * @author <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
30
 * @author <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
30
 * @since 6.0
31
 * @since 5.3
31
 */
32
 */
32
public class RuntimeInvisibleAnnotations extends Annotations
33
public class RuntimeInvisibleAnnotations extends Annotations
33
{
34
{
Lines 44-55 public class RuntimeInvisibleAnnotations extends Annotations Link Here
44
     *            Array of constants
45
     *            Array of constants
45
     */
46
     */
46
    RuntimeInvisibleAnnotations(int name_index, int length,
47
    RuntimeInvisibleAnnotations(int name_index, int length,
47
                                DataInputStream file, ConstantPool constant_pool)
48
                                DataInput file, ConstantPool constant_pool)
48
                                throws IOException
49
                                throws IOException
49
    {
50
    {
50
        super(Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS, name_index, length,
51
        super(Constants.ATTR_RUNTIMEIN_VISIBLE_ANNOTATIONS, name_index, length,
51
                file, constant_pool);
52
                file, constant_pool);
52
    }
53
    }
54
    
55
    public static void skip(int name_index, int length,
56
            DataInput file, ConstantPool constant_pool)
57
            throws IOException
58
    {
59
    	Annotations.skip(Constants.ATTR_RUNTIMEIN_VISIBLE_ANNOTATIONS, name_index, length, 
60
    			file, constant_pool);
61
    }
53
62
54
    /**
63
    /**
55
     * @return deep copy of this attribute
64
     * @return deep copy of this attribute
(-)a/java/org/apache/tomcat/util/bcel/classfile/RuntimeInvisibleParameterAnnotations.java (-4 / +10 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 26-33 import org.apache.tomcat.util.bcel.Constants; Link Here
26
 * represents a parameter annotation that is represented in the class file
26
 * represents a parameter annotation that is represented in the class file
27
 * but is not provided to the JVM.
27
 * but is not provided to the JVM.
28
 * 
28
 * 
29
 * @version $Id: RuntimeInvisibleParameterAnnotations
29
 * @author  <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
30
 * @author  <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
30
 * @since 6.0
31
 * @since 5.3
31
 */
32
 */
32
public class RuntimeInvisibleParameterAnnotations extends ParameterAnnotations {
33
public class RuntimeInvisibleParameterAnnotations extends ParameterAnnotations {
33
34
Lines 40-50 public class RuntimeInvisibleParameterAnnotations extends ParameterAnnotations { Link Here
40
     * @param file Input stream
41
     * @param file Input stream
41
     * @param constant_pool Array of constants
42
     * @param constant_pool Array of constants
42
     */
43
     */
43
    RuntimeInvisibleParameterAnnotations(int name_index, int length, DataInputStream file,
44
    RuntimeInvisibleParameterAnnotations(int name_index, int length, DataInput file,
44
            ConstantPool constant_pool) throws IOException {
45
            ConstantPool constant_pool) throws IOException {
45
        super(Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file,
46
        super(Constants.ATTR_RUNTIMEIN_VISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file,
46
                constant_pool);
47
                constant_pool);
47
    }
48
    }
49
    
50
    public static void skip(int name_index, int length, DataInput file,
51
            ConstantPool constant_pool) throws IOException {
52
    	ParameterAnnotations.skip(Constants.ATTR_RUNTIMEIN_VISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file, constant_pool);
53
    }
48
54
49
55
50
    /**
56
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/RuntimeVisibleAnnotations.java (-3 / +11 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 26-33 import org.apache.tomcat.util.bcel.Constants; Link Here
26
 * represents an annotation that is represented in the class file and is
26
 * represents an annotation that is represented in the class file and is
27
 * provided to the JVM.
27
 * provided to the JVM.
28
 * 
28
 * 
29
 * @version $Id: RuntimeVisibleAnnotations
29
 * @author <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
30
 * @author <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
30
 * @since 6.0
31
 * @since 5.3
31
 */
32
 */
32
public class RuntimeVisibleAnnotations extends Annotations
33
public class RuntimeVisibleAnnotations extends Annotations
33
{
34
{
Lines 44-55 public class RuntimeVisibleAnnotations extends Annotations Link Here
44
     *            Array of constants
45
     *            Array of constants
45
     */
46
     */
46
    public RuntimeVisibleAnnotations(int name_index, int length,
47
    public RuntimeVisibleAnnotations(int name_index, int length,
47
            DataInputStream file, ConstantPool constant_pool)
48
            DataInput file, ConstantPool constant_pool)
48
            throws IOException
49
            throws IOException
49
    {
50
    {
50
        super(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS, name_index, length,
51
        super(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS, name_index, length,
51
                file, constant_pool);
52
                file, constant_pool);
52
    }
53
    }
54
    
55
    public static void skip(int name_index, int length,
56
            DataInput file, ConstantPool constant_pool)
57
            throws IOException
58
    {
59
    	Annotations.skip(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS, name_index, length, file, constant_pool);
60
    }
53
61
54
    /**
62
    /**
55
     * @return deep copy of this attribute
63
     * @return deep copy of this attribute
(-)a/java/org/apache/tomcat/util/bcel/classfile/RuntimeVisibleParameterAnnotations.java (-3 / +9 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 26-33 import org.apache.tomcat.util.bcel.Constants; Link Here
26
 * represents a parameter annotation that is represented in the class file
26
 * represents a parameter annotation that is represented in the class file
27
 * and is provided to the JVM.
27
 * and is provided to the JVM.
28
 * 
28
 * 
29
 * @version $Id: RuntimeVisibleParameterAnnotations
29
 * @author  <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
30
 * @author  <A HREF="mailto:dbrosius@qis.net">D. Brosius</A>
30
 * @since 6.0
31
 * @since 5.3
31
 */
32
 */
32
public class RuntimeVisibleParameterAnnotations extends ParameterAnnotations {
33
public class RuntimeVisibleParameterAnnotations extends ParameterAnnotations {
33
34
Lines 40-50 public class RuntimeVisibleParameterAnnotations extends ParameterAnnotations { Link Here
40
     * @param file Input stream
41
     * @param file Input stream
41
     * @param constant_pool Array of constants
42
     * @param constant_pool Array of constants
42
     */
43
     */
43
    RuntimeVisibleParameterAnnotations(int name_index, int length, DataInputStream file,
44
    RuntimeVisibleParameterAnnotations(int name_index, int length, DataInput file,
44
            ConstantPool constant_pool) throws IOException {
45
            ConstantPool constant_pool) throws IOException {
45
        super(Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file,
46
        super(Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file,
46
                constant_pool);
47
                constant_pool);
47
    }
48
    }
49
    
50
    public static void skip(int name_index, int length, DataInput file,
51
            ConstantPool constant_pool) throws IOException {
52
    	ParameterAnnotations.skip(Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file, constant_pool);
53
    }
48
54
49
55
50
    /**
56
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/Signature.java (+6 lines)
Lines 26-31 import org.apache.tomcat.util.bcel.Constants; Link Here
26
 * This class is derived from <em>Attribute</em> and represents a reference
26
 * This class is derived from <em>Attribute</em> and represents a reference
27
 * to a GJ attribute.
27
 * to a GJ attribute.
28
 *
28
 *
29
 * @version $Id$
29
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30
 * @see     Attribute
31
 * @see     Attribute
31
 */
32
 */
Lines 47-52 public final class Signature extends Attribute { Link Here
47
            throws IOException {
48
            throws IOException {
48
        this(name_index, length, file.readUnsignedShort(), constant_pool);
49
        this(name_index, length, file.readUnsignedShort(), constant_pool);
49
    }
50
    }
51
    
52
    public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
53
            throws IOException {
54
    	file.skipBytes(2);
55
    }
50
56
51
57
52
    /**
58
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/SimpleElementValue.java (-2 / +2 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataOutputStream;
20
import java.io.DataOutput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 100-106 public class SimpleElementValue extends ElementValue Link Here
100
    }
100
    }
101
101
102
    @Override
102
    @Override
103
    public void dump(DataOutputStream dos) throws IOException
103
    public void dump(DataOutput dos) throws IOException
104
    {
104
    {
105
        dos.writeByte(type); // u1 kind of value
105
        dos.writeByte(type); // u1 kind of value
106
        switch (type)
106
        switch (type)
(-)a/java/org/apache/tomcat/util/bcel/classfile/SourceFile.java (+6 lines)
Lines 28-33 import org.apache.tomcat.util.bcel.Constants; Link Here
28
 * should appear per classfile.  The intention of this class is that it is
28
 * should appear per classfile.  The intention of this class is that it is
29
 * instantiated from the <em>Attribute.readAttribute()</em> method.
29
 * instantiated from the <em>Attribute.readAttribute()</em> method.
30
 *
30
 *
31
 * @version $Id$
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32
 * @see     Attribute
33
 * @see     Attribute
33
 */
34
 */
Lines 49-54 public final class SourceFile extends Attribute { Link Here
49
            throws IOException {
50
            throws IOException {
50
        this(name_index, length, file.readUnsignedShort(), constant_pool);
51
        this(name_index, length, file.readUnsignedShort(), constant_pool);
51
    }
52
    }
53
    
54
    public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
55
            throws IOException {
56
    	file.skipBytes(2);
57
    }
52
58
53
59
54
    /**
60
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/StackMap.java (-2 / +11 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 31-36 import org.apache.tomcat.util.bcel.Constants; Link Here
31
 * within the Code attribute of a method. See CLDC specification
31
 * within the Code attribute of a method. See CLDC specification
32
 * &sect;5.3.1.2
32
 * &sect;5.3.1.2
33
 *
33
 *
34
 * @version $Id$
34
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
35
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
35
 * @see     Code
36
 * @see     Code
36
 * @see     StackMapEntry
37
 * @see     StackMapEntry
Lines 63-69 public final class StackMap extends Attribute { Link Here
63
     * @param constant_pool Array of constants
64
     * @param constant_pool Array of constants
64
     * @throws IOException
65
     * @throws IOException
65
     */
66
     */
66
    StackMap(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
67
    StackMap(int name_index, int length, DataInput file, ConstantPool constant_pool)
67
            throws IOException {
68
            throws IOException {
68
        this(name_index, length, (StackMapEntry[]) null, constant_pool);
69
        this(name_index, length, (StackMapEntry[]) null, constant_pool);
69
        map_length = file.readUnsignedShort();
70
        map_length = file.readUnsignedShort();
Lines 72-77 public final class StackMap extends Attribute { Link Here
72
            map[i] = new StackMapEntry(file, constant_pool);
73
            map[i] = new StackMapEntry(file, constant_pool);
73
        }
74
        }
74
    }
75
    }
76
    
77
    public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
78
            throws IOException {
79
        int map_length = file.readUnsignedShort();
80
        for (int i = 0; i < map_length; i++) {
81
        	StackMapEntry.skip(file, constant_pool);
82
        }
83
    }
75
84
76
85
77
    /**
86
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/StackMapEntry.java (-5 / +16 lines)
Lines 17-32 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.*;
21
import java.io.DataOutputStream;
22
import java.io.IOException;
23
import java.io.Serializable;
24
21
25
/**
22
/**
26
 * This class represents a stack map entry recording the types of
23
 * This class represents a stack map entry recording the types of
27
 * local variables and the the of stack items at a given byte code offset.
24
 * local variables and the the of stack items at a given byte code offset.
28
 * See CLDC specification &sect;5.3.1.2
25
 * See CLDC specification &sect;5.3.1.2
29
 *
26
 *
27
 * @version $Id$
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
28
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31
 * @see     StackMap
29
 * @see     StackMap
32
 * @see     StackMapType
30
 * @see     StackMapType
Lines 47-53 public final class StackMapEntry implements Cloneable, Serializable { Link Here
47
     * @param file Input stream
45
     * @param file Input stream
48
     * @throws IOException
46
     * @throws IOException
49
     */
47
     */
50
    StackMapEntry(DataInputStream file, ConstantPool constant_pool) throws IOException {
48
    StackMapEntry(DataInput file, ConstantPool constant_pool) throws IOException {
51
        this(file.readShort(), file.readShort(), null, -1, null);
49
        this(file.readShort(), file.readShort(), null, -1, null);
52
        types_of_locals = new StackMapType[number_of_locals];
50
        types_of_locals = new StackMapType[number_of_locals];
53
        for (int i = 0; i < number_of_locals; i++) {
51
        for (int i = 0; i < number_of_locals; i++) {
Lines 59-64 public final class StackMapEntry implements Cloneable, Serializable { Link Here
59
            types_of_stack_items[i] = new StackMapType(file, constant_pool);
57
            types_of_stack_items[i] = new StackMapType(file, constant_pool);
60
        }
58
        }
61
    }
59
    }
60
    
61
    public static void skip(DataInput file, ConstantPool constant_pool) throws IOException {
62
//    	int byte_code_offset = file.readShort();
63
    	file.skipBytes(2);
64
        int number_of_locals = file.readShort();
65
        for (int i = 0; i < number_of_locals; i++) {
66
        	StackMapType.skip(file, constant_pool);
67
        }
68
        int number_of_stack_items = file.readShort();
69
        for (int i = 0; i < number_of_stack_items; i++) {
70
        	StackMapType.skip(file, constant_pool);
71
        }
72
    }
62
73
63
74
64
    public StackMapEntry(int byte_code_offset, int number_of_locals,
75
    public StackMapEntry(int byte_code_offset, int number_of_locals,
(-)a/java/org/apache/tomcat/util/bcel/classfile/StackMapTable.java (-2 / +11 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 31-36 import org.apache.tomcat.util.bcel.Constants; Link Here
31
 * within the Code attribute of a method. See CLDC specification
31
 * within the Code attribute of a method. See CLDC specification
32
 * &sect;5.3.1.2
32
 * &sect;5.3.1.2
33
 *
33
 *
34
 * @version $Id$
34
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
35
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
35
 * @see     Code
36
 * @see     Code
36
 * @see     StackMapEntry
37
 * @see     StackMapEntry
Lines 63-69 public final class StackMapTable extends Attribute { Link Here
63
     * @param constant_pool Array of constants
64
     * @param constant_pool Array of constants
64
     * @throws IOException
65
     * @throws IOException
65
     */
66
     */
66
    StackMapTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
67
    StackMapTable(int name_index, int length, DataInput file, ConstantPool constant_pool)
67
            throws IOException {
68
            throws IOException {
68
        this(name_index, length, (StackMapTableEntry[]) null, constant_pool);
69
        this(name_index, length, (StackMapTableEntry[]) null, constant_pool);
69
        map_length = file.readUnsignedShort();
70
        map_length = file.readUnsignedShort();
Lines 72-77 public final class StackMapTable extends Attribute { Link Here
72
            map[i] = new StackMapTableEntry(file, constant_pool);
73
            map[i] = new StackMapTableEntry(file, constant_pool);
73
        }
74
        }
74
    }
75
    }
76
    
77
    public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
78
            throws IOException {
79
    	int map_length = file.readUnsignedShort();
80
        for (int i = 0; i < map_length; i++) {
81
        	StackMapTableEntry.skip(file, constant_pool);
82
        }
83
    }
75
84
76
85
77
    /**
86
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/StackMapTableEntry.java (-6 / +38 lines)
Lines 17-26 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.*;
21
import java.io.DataOutputStream;
22
import java.io.IOException;
23
import java.io.Serializable;
24
21
25
import org.apache.tomcat.util.bcel.Constants;
22
import org.apache.tomcat.util.bcel.Constants;
26
23
Lines 29-34 import org.apache.tomcat.util.bcel.Constants; Link Here
29
 * local variables and the the of stack items at a given byte code offset.
26
 * local variables and the the of stack items at a given byte code offset.
30
 * See CLDC specification &sect;5.3.1.2
27
 * See CLDC specification &sect;5.3.1.2
31
 *
28
 *
29
 * @version $Id$
32
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
33
 * @see     StackMap
31
 * @see     StackMap
34
 * @see     StackMapType
32
 * @see     StackMapType
Lines 50-57 public final class StackMapTableEntry implements Cloneable, Serializable { Link Here
50
     * @param file Input stream
48
     * @param file Input stream
51
     * @throws IOException
49
     * @throws IOException
52
     */
50
     */
53
    StackMapTableEntry(DataInputStream file, ConstantPool constant_pool) throws IOException {
51
    StackMapTableEntry(DataInput file, ConstantPool constant_pool) throws IOException {
54
        this(file.read(), -1, -1, null, -1, null);
52
        this(file.readUnsignedByte(), -1, -1, null, -1, null);
55
        
53
        
56
        if (frame_type >= Constants.SAME_FRAME && frame_type <= Constants.SAME_FRAME_MAX) {
54
        if (frame_type >= Constants.SAME_FRAME && frame_type <= Constants.SAME_FRAME_MAX) {
57
            byte_code_offset_delta = frame_type - Constants.SAME_FRAME;
55
            byte_code_offset_delta = frame_type - Constants.SAME_FRAME;
Lines 93-98 public final class StackMapTableEntry implements Cloneable, Serializable { Link Here
93
            throw new ClassFormatException ("Invalid frame type found while parsing stack map table: " + frame_type);
91
            throw new ClassFormatException ("Invalid frame type found while parsing stack map table: " + frame_type);
94
        }
92
        }
95
    }
93
    }
94
    
95
    public static void skip(DataInput file, ConstantPool constant_pool) throws IOException {
96
    	int frame_type = file.readUnsignedByte();
97
    	if (frame_type >= Constants.SAME_FRAME && frame_type <= Constants.SAME_FRAME_MAX) {	
98
    	}else if(frame_type >= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME && frame_type <= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX){
99
    		StackMapType.skip(file, constant_pool);
100
    	}else if (frame_type == Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
101
    		file.skipBytes(2);
102
    		StackMapType.skip(file, constant_pool);
103
    	}else if (frame_type >= Constants.CHOP_FRAME && frame_type <= Constants.CHOP_FRAME_MAX){
104
    		file.skipBytes(2);
105
    	}else if (frame_type == Constants.SAME_FRAME_EXTENDED) {
106
    		file.skipBytes(2);
107
    	}else if (frame_type >= Constants.APPEND_FRAME && frame_type <= Constants.APPEND_FRAME_MAX) {
108
    		file.skipBytes(2);
109
    		int number_of_locals = frame_type - 251;
110
    		for (int i = 0; i < number_of_locals; i++) {
111
                StackMapType.skip(file, constant_pool);
112
            }   
113
    	}else if (frame_type == Constants.FULL_FRAME) { 
114
    		file.skipBytes(2);
115
            int number_of_locals = file.readShort();
116
            for (int i = 0; i < number_of_locals; i++) {
117
            	StackMapType.skip(file, constant_pool);
118
            }
119
            int number_of_stack_items = file.readShort();
120
            for (int i = 0; i < number_of_stack_items; i++) {
121
            	StackMapType.skip(file, constant_pool);
122
            }
123
    	}else {
124
            /* Can't happen */
125
            throw new ClassFormatException ("Invalid frame type found while parsing stack map table: " + frame_type);
126
        }
127
    }
96
128
97
129
98
    public StackMapTableEntry(int tag, int byte_code_offset_delta, int number_of_locals,
130
    public StackMapTableEntry(int tag, int byte_code_offset_delta, int number_of_locals,
(-)a/java/org/apache/tomcat/util/bcel/classfile/StackMapType.java (+9 lines)
Lines 28-33 import org.apache.tomcat.util.bcel.Constants; Link Here
28
 * This class represents the type of a local variable or item on stack
28
 * This class represents the type of a local variable or item on stack
29
 * used in the StackMap entries.
29
 * used in the StackMap entries.
30
 *
30
 *
31
 * @version $Id$
31
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
32
 * @see     StackMapEntry
33
 * @see     StackMapEntry
33
 * @see     StackMap
34
 * @see     StackMap
Lines 54-59 public final class StackMapType implements Cloneable, Serializable { Link Here
54
        }
55
        }
55
        setConstantPool(constant_pool);
56
        setConstantPool(constant_pool);
56
    }
57
    }
58
    
59
    // logic may be false??????????????????????????????????????
60
    public static void skip(DataInput file, ConstantPool constant_pool) throws IOException {
61
    	byte type = file.readByte();
62
        if ((type == Constants.ITEM_Object) || (type == Constants.ITEM_NewObject)) {
63
            file.skipBytes(2);
64
        }
65
    }
57
66
58
67
59
    /**
68
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/Synthetic.java (-2 / +11 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
22
23
import org.apache.tomcat.util.bcel.Constants;
23
import org.apache.tomcat.util.bcel.Constants;
Lines 31-36 import org.apache.tomcat.util.bcel.Constants; Link Here
31
 * is intended to be instantiated from the
31
 * is intended to be instantiated from the
32
 * <em>Attribute.readAttribute()</em> method.
32
 * <em>Attribute.readAttribute()</em> method.
33
 *
33
 *
34
 * @version $Id$
34
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
35
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
35
 * @see     Attribute
36
 * @see     Attribute
36
 */
37
 */
Lines 62-68 public final class Synthetic extends Attribute { Link Here
62
     * @param constant_pool Array of constants
63
     * @param constant_pool Array of constants
63
     * @throws IOException
64
     * @throws IOException
64
     */
65
     */
65
    Synthetic(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
66
    Synthetic(int name_index, int length, DataInput file, ConstantPool constant_pool)
66
            throws IOException {
67
            throws IOException {
67
        this(name_index, length, (byte[]) null, constant_pool);
68
        this(name_index, length, (byte[]) null, constant_pool);
68
        if (length > 0) {
69
        if (length > 0) {
Lines 71-76 public final class Synthetic extends Attribute { Link Here
71
            System.err.println("Synthetic attribute with length > 0");
72
            System.err.println("Synthetic attribute with length > 0");
72
        }
73
        }
73
    }
74
    }
75
    
76
    public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
77
            throws IOException {
78
    	if(length > 0){
79
    		file.skipBytes(length);
80
            System.err.println("Synthetic attribute with length > 0");
81
    	}
82
    }
74
83
75
84
76
    /**
85
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/Unknown.java (-2 / +9 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInputStream;
20
import java.io.DataInput;
21
import java.io.IOException;
21
import java.io.IOException;
22
import java.util.HashMap;
22
import java.util.HashMap;
23
import java.util.Map;
23
import java.util.Map;
Lines 35-40 import org.apache.tomcat.util.bcel.Constants; Link Here
35
 * org.apache.tomcat.util.bcel.classfile.AttributeReader)">Attribute.addAttributeReader</a>.
35
 * org.apache.tomcat.util.bcel.classfile.AttributeReader)">Attribute.addAttributeReader</a>.
36
36
37
 *
37
 *
38
 * @version $Id$
38
 * @see org.apache.tomcat.util.bcel.classfile.Attribute
39
 * @see org.apache.tomcat.util.bcel.classfile.Attribute
39
 * @see org.apache.tomcat.util.bcel.classfile.AttributeReader
40
 * @see org.apache.tomcat.util.bcel.classfile.AttributeReader
40
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
41
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
Lines 73-79 public final class Unknown extends Attribute { Link Here
73
     * @param constant_pool Array of constants
74
     * @param constant_pool Array of constants
74
     * @throws IOException
75
     * @throws IOException
75
     */
76
     */
76
    Unknown(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
77
    Unknown(int name_index, int length, DataInput file, ConstantPool constant_pool)
77
            throws IOException {
78
            throws IOException {
78
        this(name_index, length, (byte[]) null, constant_pool);
79
        this(name_index, length, (byte[]) null, constant_pool);
79
        if (length > 0) {
80
        if (length > 0) {
Lines 81-86 public final class Unknown extends Attribute { Link Here
81
            file.readFully(bytes);
82
            file.readFully(bytes);
82
        }
83
        }
83
    }
84
    }
85
    
86
    public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
87
    		throws IOException {
88
    	if(length > 0) file.skipBytes(length);
89
    	
90
    }
84
91
85
92
86
    /**
93
    /**
(-)a/java/org/apache/tomcat/util/bcel/classfile/Utility.java (-20 / +1 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
package org.apache.tomcat.util.bcel.classfile;
18
package org.apache.tomcat.util.bcel.classfile;
19
19
20
import java.io.DataInput;
21
import java.io.IOException;
20
import java.io.IOException;
22
21
23
import org.apache.tomcat.util.bcel.Constants;
22
import org.apache.tomcat.util.bcel.Constants;
Lines 26-31 import org.apache.tomcat.util.bcel.util.ByteSequence; Link Here
26
/**
25
/**
27
 * Utility functions that do not really belong to any class in particular.
26
 * Utility functions that do not really belong to any class in particular.
28
 *
27
 *
28
 * @version $Id$
29
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30
 */
30
 */
31
public abstract class Utility {
31
public abstract class Utility {
Lines 778-800 public abstract class Utility { Link Here
778
        }
778
        }
779
        return buf.toString();
779
        return buf.toString();
780
    }
780
    }
781
782
    static void swallowBootstrapMethods(DataInput file) throws IOException {
783
        int num_bootstrap_methods = file.readUnsignedShort();
784
        for (int i = 0; i < num_bootstrap_methods; i++) {
785
            file.readUnsignedShort();   // Unused bootstrap_method_ref
786
            int num_bootstrap_args = file.readUnsignedShort();
787
            for (int j = 0; j < num_bootstrap_args; j++) {
788
                file.readUnsignedShort(); // Unused bootstrap method argument
789
            }
790
        }
791
    }
792
793
    static void swallowMethodParameters(DataInput file) throws IOException {
794
        int parameters_count = file.readUnsignedByte();
795
        for (int i = 0; i < parameters_count; i++) {
796
            file.readUnsignedShort();   // Unused name_index
797
            file.readUnsignedShort();   // Unused access_flags
798
        }
799
    }
800
}
781
}
(-)a/java/org/apache/tomcat/util/bcel/classfile/package.html (+3 lines)
Lines 17-22 Link Here
17
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
17
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
18
<html>
18
<html>
19
<head>
19
<head>
20
<!--
21
$Id$
22
-->
20
</head>
23
</head>
21
<body bgcolor="white">
24
<body bgcolor="white">
22
<p>
25
<p>
(-)a/java/org/apache/tomcat/util/bcel/util/BCELComparator.java (+1 lines)
Lines 21-26 package org.apache.tomcat.util.bcel.util; Link Here
21
 * Used for BCEL comparison strategy
21
 * Used for BCEL comparison strategy
22
 * 
22
 * 
23
 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
23
 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
24
 * @version $Id$
24
 * @since 5.2
25
 * @since 5.2
25
 */
26
 */
26
public interface BCELComparator {
27
public interface BCELComparator {
(-)a/java/org/apache/tomcat/util/bcel/util/ByteSequence.java (+1 lines)
Lines 25-30 import java.io.DataInputStream; Link Here
25
 * via the `readByte()' method. This is used to implement a wrapper for the 
25
 * via the `readByte()' method. This is used to implement a wrapper for the 
26
 * Java byte code stream to gain some more readability.
26
 * Java byte code stream to gain some more readability.
27
 *
27
 *
28
 * @version $Id$
28
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29
 * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
29
 */
30
 */
30
public final class ByteSequence extends DataInputStream {
31
public final class ByteSequence extends DataInputStream {
(-)a/java/org/apache/tomcat/util/bcel/util/FastDataInputStream.java (+372 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
package org.apache.tomcat.util.bcel.util;
19
20
import java.io.DataInput;
21
import java.io.EOFException;
22
import java.io.FilterInputStream;
23
import java.io.IOException;
24
import java.io.InputStream;
25
import java.io.UTFDataFormatException;
26
27
28
/**
29
 * Created by xshao on 7/31/14.
30
 */
31
public class FastDataInputStream extends FilterInputStream implements DataInput {
32
	/**
33
     * Creates a DataInputStream that uses the specified
34
     * underlying InputStream.
35
     *
36
     * @param  in   the specified input stream
37
	 * @throws IOException 
38
     */
39
	
40
	//Buff
41
	private static int defaultBufferSize = 8192;
42
	protected volatile byte buf[];
43
    protected int cnt;
44
    protected int pos;
45
    
46
    //Constructor
47
    public FastDataInputStream(InputStream in) {
48
    	super(in);
49
    	buf = new byte[defaultBufferSize];
50
    }
51
    
52
    public FastDataInputStream(InputStream in, int size) {
53
    	super(in);
54
            if (size <= 0) {
55
                throw new IllegalArgumentException("Buffer size <= 0");
56
            }
57
    	buf = new byte[size];
58
    }
59
60
    public final int read(byte b[]) throws IOException {
61
        return this.read(b, 0, b.length);
62
    }
63
    
64
    public int read(byte b[], int off, int len)
65
            throws IOException
66
    {
67
        if ((off | len | (off + len) | (b.length - (off + len))) < 0) {
68
            throw new IndexOutOfBoundsException();
69
        } else if (len == 0) {
70
            return 0;
71
        }
72
73
        int n = 0;
74
        for (;;) {
75
            int nread = read1(b, off + n, len - n);
76
            if (nread <= 0)
77
                return (n == 0) ? nread : n;
78
            n += nread;
79
            if (n >= len)
80
                return n;
81
            // if not closed but no bytes available, return
82
            InputStream input = in;
83
            if (input != null && input.available() <= 0)
84
                return n;
85
        }
86
    }
87
    
88
    private int read1(byte[] b, int off, int len) throws IOException {
89
        int avail = cnt - pos;
90
        if (avail <= 0) {
91
            /* If the requested length is at least as large as the buffer, and
92
               if there is no mark/reset activity, do not bother to copy the
93
               bytes into the local buffer.  In this way buffered streams will
94
               cascade harmlessly. */
95
            if (len >= this.buf.length) {
96
                return this.in.read(b, off, len);
97
            }
98
            fill();
99
            avail = cnt - pos;
100
            if (avail <= 0) return -1;
101
        }
102
        int inc = (avail < len) ? avail : len;
103
        System.arraycopy(this.buf, pos, b, off, inc);
104
        pos += inc;
105
        return inc;
106
    }
107
    
108
    public final void readFully(byte b[]) throws IOException {
109
//    	System.out.println("readFully");
110
111
		readFully(b, 0, b.length);
112
	}
113
114
	@Override
115
	public final void readFully(byte b[], int off, int len) throws IOException {
116
		if (len < 0)
117
		    throw new IndexOutOfBoundsException();
118
		int n = 0;
119
		while (n < len) {
120
		    int count = this.read(b, off + n, len - n);
121
		    if (count < 0)
122
		    	throw new EOFException();
123
		    n += count;
124
		}
125
    }
126
127
	@Override
128
	public boolean readBoolean() throws IOException {
129
		if (pos >= cnt) {
130
            fill();
131
            if (pos >= cnt)
132
                throw new EOFException();
133
        }
134
		int ch = this.buf[pos++] & 0xff;
135
		return (ch != 0);
136
	}
137
	
138
    public final byte readByte() throws IOException {
139
//    	System.out.println("readByte");
140
141
    	if (pos >= cnt) {
142
            fill();
143
            if (pos >= cnt)
144
                throw new EOFException();
145
        }
146
    	return this.buf[pos++];
147
//		int ch = this.buf[pos++] & 0xff;
148
//    	return (byte)(ch);
149
    }
150
    
151
	@Override
152
	public int readUnsignedByte() throws IOException {
153
		if (pos >= cnt) {
154
            fill();
155
            if (pos >= cnt)
156
                throw new EOFException();
157
        }
158
		int ch = this.buf[pos++] & 0xff;
159
		return ch;
160
	}
161
    
162
	public final short readShort() throws IOException {
163
//    	System.out.println("readShort");
164
    	
165
    	if(pos + 1 >= cnt){
166
    		fill();
167
    		if(pos + 1 >= cnt) throw new EOFException();
168
    	}
169
    	int ch1 = this.buf[pos++] & 0xff;
170
    	int ch2 = this.buf[pos++] & 0xff;
171
        return (short)((ch1 << 8) + (ch2 << 0));
172
    }
173
	
174
    public int readUnsignedShort() throws IOException{
175
//    	System.out.println("readUnsignedShort");
176
177
    	if(pos + 1 >= cnt) {
178
    		fill();
179
    		if(pos + 1 >= cnt) throw new EOFException();
180
    	}
181
    	
182
    	int ch1 = this.buf[pos++] & 0xff;
183
    	int ch2 = this.buf[pos++] & 0xff;
184
        return (ch1 << 8) + (ch2 << 0);
185
    }
186
    
187
    public final char readChar() throws IOException {
188
//    	System.out.println("readChar");
189
190
    	if(pos + 1 >= cnt) {
191
    		fill();
192
    		if(pos + 1 >= cnt) throw new EOFException();
193
    	}
194
        int ch1 = this.buf[pos++] & 0xff;
195
        int ch2 = this.buf[pos++] & 0xff;
196
        return (char)((ch1 << 8) + (ch2 << 0));
197
    }
198
    
199
    public final int readInt() throws IOException {
200
//    	System.out.println("readInt");
201
202
    	if(pos + 3 >= cnt){
203
    		fill();
204
    		if(pos + 3 >= cnt) throw new EOFException();
205
    	}
206
    	int ch1 = this.buf[pos++] & 0xff;
207
        int ch2 = this.buf[pos++] & 0xff;
208
        int ch3 = this.buf[pos++] & 0xff;
209
        int ch4 = this.buf[pos++] & 0xff;
210
        return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
211
    }
212
    
213
    private byte readBuffer[] = new byte[8];
214
215
    public final long readLong() throws IOException {
216
        readFully(readBuffer, 0, 8);
217
        return (((long)readBuffer[0] << 56) +
218
                ((long)(readBuffer[1] & 255) << 48) +
219
                ((long)(readBuffer[2] & 255) << 40) +
220
                ((long)(readBuffer[3] & 255) << 32) +
221
                ((long)(readBuffer[4] & 255) << 24) +
222
                ((readBuffer[5] & 255) << 16) +
223
                ((readBuffer[6] & 255) <<  8) +
224
                ((readBuffer[7] & 255) <<  0));
225
    }
226
    
227
    public final float readFloat() throws IOException {
228
        return Float.intBitsToFloat(readInt());
229
    }
230
231
	@Override
232
	public double readDouble() throws IOException {
233
		return Double.longBitsToDouble(readLong());
234
	}
235
    
236
    public final String readUTF() throws IOException {
237
//    	System.out.println("readUTF");
238
239
        return readUTF(this);
240
    }
241
    
242
    private byte bytearr[] = new byte[80];
243
    private char chararr[] = new char[80];
244
    
245
    public final String readUTF(DataInput in) throws IOException {
246
        int utflen = this.readUnsignedShort();
247
        byte[] bytearr = null;
248
        char[] chararr = null;
249
        if (in instanceof FastDataInputStream) {
250
        	FastDataInputStream dis = (FastDataInputStream)in;
251
            if (dis.bytearr.length < utflen){
252
                dis.bytearr = new byte[utflen*2];
253
                dis.chararr = new char[utflen*2];
254
            }
255
            chararr = dis.chararr;
256
            bytearr = dis.bytearr;
257
        } else {
258
            bytearr = new byte[utflen];
259
            chararr = new char[utflen];
260
        }
261
262
        int c, char2, char3;
263
        int count = 0;
264
        int chararr_count=0;
265
266
        this.readFully(bytearr, 0, utflen);
267
268
        while (count < utflen) {
269
            c = (int) bytearr[count] & 0xff;      
270
            if (c > 127) break;
271
            count++;
272
            chararr[chararr_count++]=(char)c;
273
        }
274
275
        while (count < utflen) {
276
            c = (int) bytearr[count] & 0xff;
277
            switch (c >> 4) {
278
                case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
279
                    /* 0xxxxxxx*/
280
                    count++;
281
                    chararr[chararr_count++]=(char)c;
282
                    break;
283
                case 12: case 13:
284
                    /* 110x xxxx   10xx xxxx*/
285
                    count += 2;
286
                    if (count > utflen)
287
                        throw new UTFDataFormatException(
288
                            "malformed input: partial character at end");
289
                    char2 = (int) bytearr[count-1];
290
                    if ((char2 & 0xC0) != 0x80)
291
                        throw new UTFDataFormatException(
292
                            "malformed input around byte " + count); 
293
                    chararr[chararr_count++]=(char)(((c & 0x1F) << 6) | 
294
                                                    (char2 & 0x3F));  
295
                    break;
296
                case 14:
297
                    /* 1110 xxxx  10xx xxxx  10xx xxxx */
298
                    count += 3;
299
                    if (count > utflen)
300
                        throw new UTFDataFormatException(
301
                            "malformed input: partial character at end");
302
                    char2 = (int) bytearr[count-2];
303
                    char3 = (int) bytearr[count-1];
304
                    if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
305
                        throw new UTFDataFormatException(
306
                            "malformed input around byte " + (count-1));
307
                    chararr[chararr_count++]=(char)(((c     & 0x0F) << 12) |
308
                                                    ((char2 & 0x3F) << 6)  |
309
                                                    ((char3 & 0x3F) << 0));
310
                    break;
311
                default:
312
                    /* 10xx xxxx,  1111 xxxx */
313
                    throw new UTFDataFormatException(
314
                        "malformed input around byte " + count);
315
            }
316
        }
317
        // The number of chars produced may be less than utflen
318
        return new String(chararr, 0, chararr_count);
319
    }
320
    
321
    private void fill() throws IOException {
322
//    	System.out.println("fill");
323
    	int remain = 0;
324
    	if(pos < cnt){
325
        	remain = cnt - pos;
326
        	System.arraycopy(buf, cnt - remain, buf, 0, remain);
327
    	}
328
    	pos = 0;
329
    	int n = this.in.read(buf, remain, defaultBufferSize - remain);
330
    	cnt = pos + n + remain;
331
    }
332
    
333
    @Override
334
 	public int skipBytes(int n) throws IOException {
335
         int avail = cnt - pos;
336
         // total skipped
337
         int total = 0;
338
         // current skipped
339
         int cur = 0;
340
         if (avail <= 0) {
341
             /* If the requested length is at least as large as the buffer, and
342
                if there is no mark/reset activity, do not bother to copy the
343
                bytes into the local buffer.  In this way buffered streams will
344
                cascade harmlessly. */
345
         	while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
346
                 total += cur;
347
             }
348
             fill();
349
             return total;
350
         }
351
         //num in the buffer is not enough
352
         if(n > avail){
353
         	pos += avail;
354
         	total += avail;
355
         	while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
356
                 total += cur;
357
             }
358
         	fill();
359
         	return total;
360
         }
361
         //num in the buffer is 
362
     	pos += n;
363
     	return n;
364
     }
365
	
366
 // unimplemented
367
	@Override
368
	public String readLine() throws IOException {
369
		// TODO Auto-generated method stub
370
		throw new IOException();
371
	}
372
}
(-)a/test/org/apache/tomcat/util/bcel/test/TestSkip.java (+163 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.apache.tomcat.util.bcel.test;
18
19
import java.io.File;
20
import java.io.IOException;
21
import java.io.InputStream;
22
import java.net.URL;
23
24
import org.apache.tomcat.util.bcel.classfile.ClassParser;
25
import org.apache.tomcat.util.scan.Jar;
26
import org.apache.tomcat.util.scan.JarFactory;
27
import org.junit.Test;
28
29
public class TestSkip {
30
	//counter
31
	long sumOrig = 0;
32
	long sumSkip = 0;
33
	
34
	@Test
35
	public void testFDIS() throws IOException{
36
		String str = System.getProperty("java.class.path");
37
		str = str.replace('\\', '/');
38
		String paths[] = str.split(";");
39
		//warm up
40
		doWarmUp(paths);
41
		//cost without cache
42
		countSkip(paths);
43
		//cost with cache
44
		countOrig(paths);
45
		
46
		System.out.println("=====lots of jar files=====");
47
		System.out.println("Normal: " + sumOrig);
48
		System.out.println("Skip: " + sumSkip);
49
		sumOrig = 0;
50
		sumSkip = 0;
51
		countFewSkip(paths);
52
		countFewOrig(paths);
53
		System.out.println("=====few jar files=====");
54
		System.out.println("Normal: " + sumOrig);
55
		System.out.println("Skip: " + sumSkip);
56
	}
57
58
	//warm up
59
	public void doWarmUp(String[] paths) throws IOException{
60
		for(String path:paths){
61
			File file = new File(path);
62
			scanRecur(file, true);
63
			scanRecur(file, false);
64
		}
65
	}
66
	
67
	//normal scan
68
	public void countOrig(String[] paths) throws IOException{
69
		boolean isSkip = false;
70
		for(String path : paths){
71
			File file = new File(path);
72
			sumOrig += scanRecur(file, isSkip);
73
		}
74
	}
75
	
76
	//normal scan & few "jar" files
77
	public void countFewOrig(String[] paths) throws IOException{
78
		boolean isSkip = false;
79
		for(String path : paths){
80
			if(path.endsWith(".jar")){
81
				File file = new File(path);
82
				sumOrig += scanFew(file, isSkip);
83
				break;
84
			}
85
		}
86
	}
87
	
88
	//use FastDataInputStream for "jar" files
89
	public void countSkip(String[] paths) throws IOException{
90
		boolean isSkip = true;
91
		for(String path : paths){
92
			File file = new File(path);
93
			sumSkip += scanRecur(file, isSkip);
94
		}
95
	}
96
	
97
	//use FastDataInputStream & one "jar" file
98
		public void countFewSkip(String[] paths) throws IOException{
99
			boolean isSkip = true;
100
			for(String path : paths){
101
				if(path.endsWith(".jar")){
102
					File file = new File(path);
103
					sumSkip += scanFew(file, isSkip);
104
					break;
105
				}
106
			}
107
		}
108
	
109
	//scan jars recursively, so that the number of jar is big.
110
	//"isSkip" indicates the parse model, 
111
	//"true" means skip some information in the class, "false" means parses normally.   
112
	public long scanRecur(File file, boolean isSkip) throws IOException{
113
		String uri = file.toURI().toString();
114
		if(uri.endsWith(".jar")){
115
			URL jarUrl = new URL("jar:" + uri + "!/");
116
			long span = doProcess(jarUrl, isSkip);
117
			return span;
118
		}
119
		else if(file.isDirectory()){
120
			for(File var : file.listFiles()){
121
				scanRecur(var, isSkip);
122
			}
123
			return 0;
124
		}
125
		else return 0;
126
	}
127
	
128
	//scan few "jar" files
129
	public long scanFew(File file, boolean isSkip) throws IOException{
130
		String uri = file.toURI().toString();
131
		if(uri.endsWith(".jar")){
132
			URL jarUrl = new URL("jar:" + uri + "!/");
133
			long span = doProcess(jarUrl, isSkip);
134
			return span;
135
		}
136
		else return 0;
137
	}
138
	
139
	//parse & count the cost
140
	public static long doProcess(URL jarUrl, boolean isSkip) throws IOException{
141
		ClassParser.isSkip = isSkip;
142
		long span = 0;
143
		Jar jar = null;
144
		jar = JarFactory.newInstance(jarUrl);
145
		jar.nextEntry();
146
        String entryName = jar.getEntryName();
147
        while (entryName != null) {
148
            //Get ".class" entries
149
            if (entryName.endsWith(".class")) {
150
            	InputStream di = jar.getEntryInputStream();
151
            	ClassParser parser = new ClassParser(di, null);
152
        		long start = System.currentTimeMillis();
153
            	parser.parse();
154
        		long end = System.currentTimeMillis();
155
        		span += (end - start);
156
157
            }
158
            jar.nextEntry();
159
            entryName = jar.getEntryName();
160
        }
161
        return span;
162
	}
163
}

Return to bug 56955