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

(-)v0/src/java/org/apache/bcel/classfile/Attribute.java (-4 / +8 lines)
Lines 83-89 Link Here
83
        file.writeInt(length);
83
        file.writeInt(length);
84
    }
84
    }
85
85
86
    private static Map readers = new HashMap();
86
    private static ThreadLocal readers = new ThreadLocal() {
87
        protected Object initialValue() {
88
            return new HashMap();
89
        }
90
    };
87
91
88
92
89
    /** Add an Attribute reader capable of parsing (user-defined) attributes
93
    /** Add an Attribute reader capable of parsing (user-defined) attributes
Lines 94-100 Link Here
94
     * @param r the reader object
98
     * @param r the reader object
95
     */
99
     */
96
    public static void addAttributeReader( String name, AttributeReader r ) {
100
    public static void addAttributeReader( String name, AttributeReader r ) {
97
        readers.put(name, r);
101
        ((Map) readers.get()).put(name, r);
98
    }
102
    }
99
103
100
104
Lines 103-109 Link Here
103
     * @param name the name of the attribute as stored in the class file
107
     * @param name the name of the attribute as stored in the class file
104
     */
108
     */
105
    public static void removeAttributeReader( String name ) {
109
    public static void removeAttributeReader( String name ) {
106
        readers.remove(name);
110
        ((Map) readers.get()).remove(name);
107
    }
111
    }
108
112
109
113
Lines 142-148 Link Here
142
        // Call proper constructor, depending on `tag'
146
        // Call proper constructor, depending on `tag'
143
        switch (tag) {
147
        switch (tag) {
144
            case Constants.ATTR_UNKNOWN:
148
            case Constants.ATTR_UNKNOWN:
145
                AttributeReader r = (AttributeReader) readers.get(name);
149
                AttributeReader r = (AttributeReader) ((Map) readers.get()).get(name);
146
                if (r != null) {
150
                if (r != null) {
147
                    return r.createAttribute(name_index, length, file, constant_pool);
151
                    return r.createAttribute(name_index, length, file, constant_pool);
148
                }
152
                }
(-)v0/src/java/org/apache/bcel/classfile/Constant.java (-5 / +13 lines)
Lines 33-39 Link Here
33
 */
33
 */
34
public abstract class Constant implements Cloneable, Node, Serializable {
34
public abstract class Constant implements Cloneable, Node, Serializable {
35
35
36
    private static BCELComparator _cmp = new BCELComparator() {
36
    private static final BCELComparator DEFAULT_CMP = new BCELComparator() {
37
37
38
        public boolean equals( Object o1, Object o2 ) {
38
        public boolean equals( Object o1, Object o2 ) {
39
            Constant THIS = (Constant) o1;
39
            Constant THIS = (Constant) o1;
Lines 47-52 Link Here
47
            return THIS.toString().hashCode();
47
            return THIS.toString().hashCode();
48
        }
48
        }
49
    };
49
    };
50
51
52
    private static ThreadLocal _cmp = new ThreadLocal() {
53
        protected Object initialValue() {
54
            return DEFAULT_CMP;
55
        }
56
    };
57
50
    /* In fact this tag is redundant since we can distinguish different
58
    /* In fact this tag is redundant since we can distinguish different
51
     * `Constant' objects by their type, i.e., via `instanceof'. In some
59
     * `Constant' objects by their type, i.e., via `instanceof'. In some
52
     * places we will use the tag for switch()es anyway.
60
     * places we will use the tag for switch()es anyway.
Lines 152-158 Link Here
152
     * @return Comparison strategy object
160
     * @return Comparison strategy object
153
     */
161
     */
154
    public static BCELComparator getComparator() {
162
    public static BCELComparator getComparator() {
155
        return _cmp;
163
        return (BCELComparator) _cmp.get();
156
    }
164
    }
157
165
158
166
Lines 160-166 Link Here
160
     * @param comparator Comparison strategy object
168
     * @param comparator Comparison strategy object
161
     */
169
     */
162
    public static void setComparator( BCELComparator comparator ) {
170
    public static void setComparator( BCELComparator comparator ) {
163
        _cmp = comparator;
171
        _cmp.set(comparator);
164
    }
172
    }
165
173
166
174
Lines 172-178 Link Here
172
     * @see java.lang.Object#equals(java.lang.Object)
180
     * @see java.lang.Object#equals(java.lang.Object)
173
     */
181
     */
174
    public boolean equals( Object obj ) {
182
    public boolean equals( Object obj ) {
175
        return _cmp.equals(this, obj);
183
        return getComparator().equals(this, obj);
176
    }
184
    }
177
185
178
186
Lines 183-188 Link Here
183
     * @see java.lang.Object#hashCode()
191
     * @see java.lang.Object#hashCode()
184
     */
192
     */
185
    public int hashCode() {
193
    public int hashCode() {
186
        return _cmp.hashCode(this);
194
        return getComparator().hashCode(this);
187
    }
195
    }
188
}
196
}
(-)v0/src/java/org/apache/bcel/classfile/Field.java (-5 / +11 lines)
Lines 31-37 Link Here
31
 */
31
 */
32
public final class Field extends FieldOrMethod {
32
public final class Field extends FieldOrMethod {
33
33
34
    private static BCELComparator _cmp = new BCELComparator() {
34
    private static final BCELComparator DEFAULT_CMP = new BCELComparator() {
35
35
36
        public boolean equals( Object o1, Object o2 ) {
36
        public boolean equals( Object o1, Object o2 ) {
37
            Field THIS = (Field) o1;
37
            Field THIS = (Field) o1;
Lines 47-52 Link Here
47
        }
47
        }
48
    };
48
    };
49
49
50
    private static ThreadLocal _cmp = new ThreadLocal() {
51
        protected Object initialValue() {
52
            return DEFAULT_CMP;
53
        }
54
    };
55
50
56
51
    /**
57
    /**
52
     * Initialize from another object. Note that both objects use the same
58
     * Initialize from another object. Note that both objects use the same
Lines 154-160 Link Here
154
     * @return Comparison strategy object
160
     * @return Comparison strategy object
155
     */
161
     */
156
    public static BCELComparator getComparator() {
162
    public static BCELComparator getComparator() {
157
        return _cmp;
163
        return (BCELComparator) _cmp.get();
158
    }
164
    }
159
165
160
166
Lines 162-168 Link Here
162
     * @param comparator Comparison strategy object
168
     * @param comparator Comparison strategy object
163
     */
169
     */
164
    public static void setComparator( BCELComparator comparator ) {
170
    public static void setComparator( BCELComparator comparator ) {
165
        _cmp = comparator;
171
        _cmp.set(comparator);
166
    }
172
    }
167
173
168
174
Lines 174-180 Link Here
174
     * @see java.lang.Object#equals(java.lang.Object)
180
     * @see java.lang.Object#equals(java.lang.Object)
175
     */
181
     */
176
    public boolean equals( Object obj ) {
182
    public boolean equals( Object obj ) {
177
        return _cmp.equals(this, obj);
183
        return getComparator().equals(this, obj);
178
    }
184
    }
179
185
180
186
Lines 185-190 Link Here
185
     * @see java.lang.Object#hashCode()
191
     * @see java.lang.Object#hashCode()
186
     */
192
     */
187
    public int hashCode() {
193
    public int hashCode() {
188
        return _cmp.hashCode(this);
194
        return getComparator().hashCode(this);
189
    }
195
    }
190
}
196
}
(-)v0/src/java/org/apache/bcel/classfile/JavaClass.java (-6 / +18 lines)
Lines 16-21 Link Here
16
 */
16
 */
17
package org.apache.bcel.classfile;
17
package org.apache.bcel.classfile;
18
18
19
import java.io.BufferedOutputStream;
19
import java.io.ByteArrayOutputStream;
20
import java.io.ByteArrayOutputStream;
20
import java.io.DataOutputStream;
21
import java.io.DataOutputStream;
21
import java.io.File;
22
import java.io.File;
Lines 67-73 Link Here
67
    public static final byte ZIP = 3;
68
    public static final byte ZIP = 3;
68
    static boolean debug = false; // Debugging on/off
69
    static boolean debug = false; // Debugging on/off
69
    static char sep = '/'; // directory separator
70
    static char sep = '/'; // directory separator
70
    private static BCELComparator _cmp = new BCELComparator() {
71
72
    private static final BCELComparator DEFAULT_CMP = new BCELComparator() {
71
73
72
        public boolean equals( Object o1, Object o2 ) {
74
        public boolean equals( Object o1, Object o2 ) {
73
            JavaClass THIS = (JavaClass) o1;
75
            JavaClass THIS = (JavaClass) o1;
Lines 81-86 Link Here
81
            return THIS.getClassName().hashCode();
83
            return THIS.getClassName().hashCode();
82
        }
84
        }
83
    };
85
    };
86
87
88
    private static ThreadLocal _cmp = new ThreadLocal() {
89
        protected Object initialValue() {
90
            return DEFAULT_CMP;
91
        }
92
    };
93
84
    /**
94
    /**
85
     * In cases where we go ahead and create something,
95
     * In cases where we go ahead and create something,
86
     * use the default SyntheticRepository, because we
96
     * use the default SyntheticRepository, because we
Lines 228-234 Link Here
228
        }
238
        }
229
        DataOutputStream dos = null;
239
        DataOutputStream dos = null;
230
        try {
240
        try {
231
            dos = new DataOutputStream(new FileOutputStream(file));
241
            dos = new DataOutputStream(
242
                new BufferedOutputStream(
243
                    new FileOutputStream(file)));
232
            dump(dos);
244
            dump(dos);
233
        } finally {
245
        } finally {
234
            if (dos != null) {
246
            if (dos != null) {
Lines 821-827 Link Here
821
     * @return Comparison strategy object
833
     * @return Comparison strategy object
822
     */
834
     */
823
    public static BCELComparator getComparator() {
835
    public static BCELComparator getComparator() {
824
        return _cmp;
836
        return (BCELComparator) _cmp.get();
825
    }
837
    }
826
838
827
839
Lines 829-835 Link Here
829
     * @param comparator Comparison strategy object
841
     * @param comparator Comparison strategy object
830
     */
842
     */
831
    public static void setComparator( BCELComparator comparator ) {
843
    public static void setComparator( BCELComparator comparator ) {
832
        _cmp = comparator;
844
        _cmp.set(comparator);
833
    }
845
    }
834
846
835
847
Lines 841-847 Link Here
841
     * @see java.lang.Object#equals(java.lang.Object)
853
     * @see java.lang.Object#equals(java.lang.Object)
842
     */
854
     */
843
    public boolean equals( Object obj ) {
855
    public boolean equals( Object obj ) {
844
        return _cmp.equals(this, obj);
856
        return getComparator().equals(this, obj);
845
    }
857
    }
846
858
847
859
Lines 861-866 Link Here
861
     * @see java.lang.Object#hashCode()
873
     * @see java.lang.Object#hashCode()
862
     */
874
     */
863
    public int hashCode() {
875
    public int hashCode() {
864
        return _cmp.hashCode(this);
876
        return getComparator().hashCode(this);
865
    }
877
    }
866
}
878
}
(-)v0/src/java/org/apache/bcel/classfile/Method.java (-5 / +10 lines)
Lines 32-38 Link Here
32
 */
32
 */
33
public final class Method extends FieldOrMethod {
33
public final class Method extends FieldOrMethod {
34
34
35
    private static BCELComparator _cmp = new BCELComparator() {
35
    private static final BCELComparator DEFAULT_CMP = new BCELComparator() {
36
36
37
        public boolean equals( Object o1, Object o2 ) {
37
        public boolean equals( Object o1, Object o2 ) {
38
            Method THIS = (Method) o1;
38
            Method THIS = (Method) o1;
Lines 48-53 Link Here
48
        }
48
        }
49
    };
49
    };
50
50
51
    private static ThreadLocal _cmp = new ThreadLocal() {
52
        protected Object initialValue() {
53
            return DEFAULT_CMP;
54
        }
55
    };
51
56
52
    /**
57
    /**
53
     * Empty constructor, all attributes have to be defined via `setXXX'
58
     * Empty constructor, all attributes have to be defined via `setXXX'
Lines 218-224 Link Here
218
     * @return Comparison strategy object
223
     * @return Comparison strategy object
219
     */
224
     */
220
    public static BCELComparator getComparator() {
225
    public static BCELComparator getComparator() {
221
        return _cmp;
226
        return (BCELComparator) _cmp.get();
222
    }
227
    }
223
228
224
229
Lines 226-232 Link Here
226
     * @param comparator Comparison strategy object
231
     * @param comparator Comparison strategy object
227
     */
232
     */
228
    public static void setComparator( BCELComparator comparator ) {
233
    public static void setComparator( BCELComparator comparator ) {
229
        _cmp = comparator;
234
        _cmp.set(comparator);
230
    }
235
    }
231
236
232
237
Lines 238-244 Link Here
238
     * @see java.lang.Object#equals(java.lang.Object)
243
     * @see java.lang.Object#equals(java.lang.Object)
239
     */
244
     */
240
    public boolean equals( Object obj ) {
245
    public boolean equals( Object obj ) {
241
        return _cmp.equals(this, obj);
246
        return getComparator().equals(this, obj);
242
    }
247
    }
243
248
244
249
Lines 249-254 Link Here
249
     * @see java.lang.Object#hashCode()
254
     * @see java.lang.Object#hashCode()
250
     */
255
     */
251
    public int hashCode() {
256
    public int hashCode() {
252
        return _cmp.hashCode(this);
257
        return getComparator().hashCode(this);
253
    }
258
    }
254
}
259
}
(-)v0/src/java/org/apache/bcel/classfile/Unknown.java (-5 / +10 lines)
Lines 44-61 Link Here
44
44
45
    private byte[] bytes;
45
    private byte[] bytes;
46
    private String name;
46
    private String name;
47
    private static Map unknown_attributes = new HashMap();
47
    private static ThreadLocal unknown_attributes = new ThreadLocal() {
48
        protected Object initialValue() {
49
            return new HashMap();
50
        }
51
    };
48
52
49
53
50
    /** @return array of unknown attributes, but just one for each kind.
54
    /** @return array of unknown attributes, but just one for each kind.
51
     */
55
     */
52
    static Unknown[] getUnknownAttributes() {
56
    static Unknown[] getUnknownAttributes() {
53
        Unknown[] unknowns = new Unknown[unknown_attributes.size()];
57
        Map map = (Map) unknown_attributes.get();
54
        Iterator entries = unknown_attributes.values().iterator();
58
        Unknown[] unknowns = new Unknown[map.size()];
59
        Iterator entries = map.values().iterator();
55
        for (int i = 0; entries.hasNext(); i++) {
60
        for (int i = 0; entries.hasNext(); i++) {
56
            unknowns[i] = (Unknown) entries.next();
61
            unknowns[i] = (Unknown) entries.next();
57
        }
62
        }
58
        unknown_attributes.clear();
63
        map.clear();
59
        return unknowns;
64
        return unknowns;
60
    }
65
    }
61
66
Lines 82-88 Link Here
82
        this.bytes = bytes;
87
        this.bytes = bytes;
83
        name = ((ConstantUtf8) constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8))
88
        name = ((ConstantUtf8) constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8))
84
                .getBytes();
89
                .getBytes();
85
        unknown_attributes.put(name, this);
90
        ((Map) unknown_attributes.get()).put(name, this);
86
    }
91
    }
87
92
88
93
(-)v0/src/java/org/apache/bcel/classfile/Utility.java (-6 / +7 lines)
Lines 62-68 Link Here
62
     * Read by methodSignatureToString().
62
     * Read by methodSignatureToString().
63
     * Set by side effect,but only internally.
63
     * Set by side effect,but only internally.
64
     */
64
     */
65
    private static boolean wide = false; /* The `WIDE' instruction is used in the
65
    private static ThreadLocal wide = new ThreadLocal();
66
    /* The `WIDE' instruction is used in the
66
     * byte code to allow 16-bit wide indices
67
     * byte code to allow 16-bit wide indices
67
     * for local variables. This opcode
68
     * for local variables. This opcode
68
     * precedes an `ILOAD', e.g.. The opcode
69
     * precedes an `ILOAD', e.g.. The opcode
Lines 285-293 Link Here
285
            case Constants.LLOAD:
286
            case Constants.LLOAD:
286
            case Constants.LSTORE:
287
            case Constants.LSTORE:
287
            case Constants.RET:
288
            case Constants.RET:
288
                if (wide) {
289
                if (wide.get() != null) {
289
                    vindex = bytes.readUnsignedShort();
290
                    vindex = bytes.readUnsignedShort();
290
                    wide = false; // Clear flag
291
                    wide.set(null); // Clear flag
291
                } else {
292
                } else {
292
                    vindex = bytes.readUnsignedByte();
293
                    vindex = bytes.readUnsignedByte();
293
                }
294
                }
Lines 299-305 Link Here
299
             * the following opcode.
300
             * the following opcode.
300
             */
301
             */
301
            case Constants.WIDE:
302
            case Constants.WIDE:
302
                wide = true;
303
                wide.set(Boolean.TRUE);
303
                buf.append("\t(wide)");
304
                buf.append("\t(wide)");
304
                break;
305
                break;
305
            /* Array of basic type.
306
            /* Array of basic type.
Lines 386-395 Link Here
386
            /* Increment local variable.
387
            /* Increment local variable.
387
             */
388
             */
388
            case Constants.IINC:
389
            case Constants.IINC:
389
                if (wide) {
390
                if (wide.get() != null) {
390
                    vindex = bytes.readUnsignedShort();
391
                    vindex = bytes.readUnsignedShort();
391
                    constant = bytes.readShort();
392
                    constant = bytes.readShort();
392
                    wide = false;
393
                    wide.set(null);
393
                } else {
394
                } else {
394
                    vindex = bytes.readUnsignedByte();
395
                    vindex = bytes.readUnsignedByte();
395
                    constant = bytes.readByte();
396
                    constant = bytes.readByte();
(-)v0/src/java/org/apache/bcel/generic/BranchHandle.java (-6 / +6 lines)
Lines 40-54 Link Here
40
40
41
    /** Factory methods.
41
    /** Factory methods.
42
     */
42
     */
43
    private static BranchHandle bh_list = null; // List of reusable handles
43
    private static ThreadLocal bh_list = new ThreadLocal(); // List of reusable handles
44
44
45
45
46
    static final BranchHandle getBranchHandle( BranchInstruction i ) {
46
    static final BranchHandle getBranchHandle( BranchInstruction i ) {
47
        if (bh_list == null) {
47
        if (bh_list.get() == null) {
48
            return new BranchHandle(i);
48
            return new BranchHandle(i);
49
        }
49
        }
50
        BranchHandle bh = bh_list;
50
        BranchHandle bh = (BranchHandle) bh_list.get();
51
        bh_list = (BranchHandle) bh.next;
51
        bh_list.set(bh.next);
52
        bh.setInstruction(i);
52
        bh.setInstruction(i);
53
        return bh;
53
        return bh;
54
    }
54
    }
Lines 57-64 Link Here
57
    /** Handle adds itself to the list of resuable handles.
57
    /** Handle adds itself to the list of resuable handles.
58
     */
58
     */
59
    protected void addHandle() {
59
    protected void addHandle() {
60
        next = bh_list;
60
        next = (BranchHandle) bh_list.get();
61
        bh_list = this;
61
        bh_list.set(this);
62
    }
62
    }
63
63
64
64
(-)v0/src/java/org/apache/bcel/generic/ClassGen.java (-5 / +12 lines)
Lines 50-56 Link Here
50
    private List method_vec = new ArrayList();
50
    private List method_vec = new ArrayList();
51
    private List attribute_vec = new ArrayList();
51
    private List attribute_vec = new ArrayList();
52
    private List interface_vec = new ArrayList();
52
    private List interface_vec = new ArrayList();
53
    private static BCELComparator _cmp = new BCELComparator() {
53
54
    private static final BCELComparator DEFAULT_CMP = new BCELComparator() {
54
55
55
        public boolean equals( Object o1, Object o2 ) {
56
        public boolean equals( Object o1, Object o2 ) {
56
            ClassGen THIS = (ClassGen) o1;
57
            ClassGen THIS = (ClassGen) o1;
Lines 65-70 Link Here
65
        }
66
        }
66
    };
67
    };
67
68
69
    private static ThreadLocal _cmp = new ThreadLocal() {
70
        protected Object initialValue() {
71
            return DEFAULT_CMP;
72
        }
73
    };
74
68
75
69
    /** Convenience constructor to set up some important values initially.
76
    /** Convenience constructor to set up some important values initially.
70
     *
77
     *
Lines 505-511 Link Here
505
     * @return Comparison strategy object
512
     * @return Comparison strategy object
506
     */
513
     */
507
    public static BCELComparator getComparator() {
514
    public static BCELComparator getComparator() {
508
        return _cmp;
515
        return (BCELComparator) _cmp.get();
509
    }
516
    }
510
517
511
518
Lines 513-519 Link Here
513
     * @param comparator Comparison strategy object
520
     * @param comparator Comparison strategy object
514
     */
521
     */
515
    public static void setComparator( BCELComparator comparator ) {
522
    public static void setComparator( BCELComparator comparator ) {
516
        _cmp = comparator;
523
        _cmp.set(comparator);
517
    }
524
    }
518
525
519
526
Lines 525-531 Link Here
525
     * @see java.lang.Object#equals(java.lang.Object)
532
     * @see java.lang.Object#equals(java.lang.Object)
526
     */
533
     */
527
    public boolean equals( Object obj ) {
534
    public boolean equals( Object obj ) {
528
        return _cmp.equals(this, obj);
535
        return getComparator().equals(this, obj);
529
    }
536
    }
530
537
531
538
Lines 536-541 Link Here
536
     * @see java.lang.Object#hashCode()
543
     * @see java.lang.Object#hashCode()
537
     */
544
     */
538
    public int hashCode() {
545
    public int hashCode() {
539
        return _cmp.hashCode(this);
546
        return getComparator().hashCode(this);
540
    }
547
    }
541
}
548
}
(-)v0/src/java/org/apache/bcel/generic/FieldGen.java (-5 / +10 lines)
Lines 41-47 Link Here
41
public class FieldGen extends FieldGenOrMethodGen {
41
public class FieldGen extends FieldGenOrMethodGen {
42
42
43
    private Object value = null;
43
    private Object value = null;
44
    private static BCELComparator _cmp = new BCELComparator() {
44
    private static final BCELComparator DEFAULT_CMP = new BCELComparator() {
45
45
46
        public boolean equals( Object o1, Object o2 ) {
46
        public boolean equals( Object o1, Object o2 ) {
47
            FieldGen THIS = (FieldGen) o1;
47
            FieldGen THIS = (FieldGen) o1;
Lines 57-62 Link Here
57
        }
57
        }
58
    };
58
    };
59
59
60
    private static ThreadLocal _cmp = new ThreadLocal() {
61
        protected Object initialValue() {
62
            return DEFAULT_CMP;
63
        }
64
    };
60
65
61
    /**
66
    /**
62
     * Declare a field. If it is static (isStatic() == true) and has a
67
     * Declare a field. If it is static (isStatic() == true) and has a
Lines 321-327 Link Here
321
     * @return Comparison strategy object
326
     * @return Comparison strategy object
322
     */
327
     */
323
    public static BCELComparator getComparator() {
328
    public static BCELComparator getComparator() {
324
        return _cmp;
329
        return (BCELComparator) _cmp.get();
325
    }
330
    }
326
331
327
332
Lines 329-335 Link Here
329
     * @param comparator Comparison strategy object
334
     * @param comparator Comparison strategy object
330
     */
335
     */
331
    public static void setComparator( BCELComparator comparator ) {
336
    public static void setComparator( BCELComparator comparator ) {
332
        _cmp = comparator;
337
        _cmp.set(comparator);
333
    }
338
    }
334
339
335
340
Lines 341-347 Link Here
341
     * @see java.lang.Object#equals(java.lang.Object)
346
     * @see java.lang.Object#equals(java.lang.Object)
342
     */
347
     */
343
    public boolean equals( Object obj ) {
348
    public boolean equals( Object obj ) {
344
        return _cmp.equals(this, obj);
349
        return getComparator().equals(this, obj);
345
    }
350
    }
346
351
347
352
Lines 352-357 Link Here
352
     * @see java.lang.Object#hashCode()
357
     * @see java.lang.Object#hashCode()
353
     */
358
     */
354
    public int hashCode() {
359
    public int hashCode() {
355
        return _cmp.hashCode(this);
360
        return getComparator().hashCode(this);
356
    }
361
    }
357
}
362
}
(-)v0/src/java/org/apache/bcel/generic/InstructionHandle.java (-6 / +6 lines)
Lines 99-115 Link Here
99
        setInstruction(i);
99
        setInstruction(i);
100
    }
100
    }
101
101
102
    private static InstructionHandle ih_list = null; // List of reusable handles
102
    private static ThreadLocal ih_list = new ThreadLocal(); // List of reusable handles
103
103
104
104
105
    /** Factory method.
105
    /** Factory method.
106
     */
106
     */
107
    static final InstructionHandle getInstructionHandle( Instruction i ) {
107
    static final InstructionHandle getInstructionHandle( Instruction i ) {
108
        if (ih_list == null) {
108
        if (ih_list.get() == null) {
109
            return new InstructionHandle(i);
109
            return new InstructionHandle(i);
110
        } else {
110
        } else {
111
            InstructionHandle ih = ih_list;
111
            InstructionHandle ih = (InstructionHandle) ih_list.get();
112
            ih_list = ih.next;
112
            ih_list.set(ih.next);
113
            ih.setInstruction(i);
113
            ih.setInstruction(i);
114
            return ih;
114
            return ih;
115
        }
115
        }
Lines 152-159 Link Here
152
    /** Overridden in BranchHandle
152
    /** Overridden in BranchHandle
153
     */
153
     */
154
    protected void addHandle() {
154
    protected void addHandle() {
155
        next = ih_list;
155
        next = (InstructionHandle) ih_list.get();
156
        ih_list = this;
156
        ih_list.set(this);
157
    }
157
    }
158
158
159
159
(-)v0/src/java/org/apache/bcel/generic/Instruction.java (-4 / +8 lines)
Lines 34-40 Link Here
34
34
35
    protected short length = 1; // Length of instruction in bytes 
35
    protected short length = 1; // Length of instruction in bytes 
36
    protected short opcode = -1; // Opcode number
36
    protected short opcode = -1; // Opcode number
37
    private static InstructionComparator cmp = InstructionComparator.DEFAULT;
37
    private static ThreadLocal cmp = new ThreadLocal() {
38
        protected Object initialValue() {
39
            return InstructionComparator.DEFAULT;
40
        }
41
    };
38
42
39
43
40
    /**
44
    /**
Lines 272-285 Link Here
272
     * @return currently used comparator for equals()
276
     * @return currently used comparator for equals()
273
     */
277
     */
274
    public static InstructionComparator getComparator() {
278
    public static InstructionComparator getComparator() {
275
        return cmp;
279
        return (InstructionComparator) cmp.get();
276
    }
280
    }
277
281
278
282
279
    /** Set comparator to be used for equals().
283
    /** Set comparator to be used for equals().
280
     */
284
     */
281
    public static void setComparator( InstructionComparator c ) {
285
    public static void setComparator( InstructionComparator c ) {
282
        cmp = c;
286
        cmp.set(c);
283
    }
287
    }
284
288
285
289
Lines 287-292 Link Here
287
     * @return true if that is an Instruction and has the same opcode
291
     * @return true if that is an Instruction and has the same opcode
288
     */
292
     */
289
    public boolean equals( Object that ) {
293
    public boolean equals( Object that ) {
290
        return (that instanceof Instruction) ? cmp.equals(this, (Instruction) that) : false;
294
        return (that instanceof Instruction) ? getComparator().equals(this, (Instruction) that) : false;
291
    }
295
    }
292
}
296
}
(-)v0/src/java/org/apache/bcel/generic/MethodGen.java (-5 / +11 lines)
Lines 64-70 Link Here
64
    private List exception_vec = new ArrayList();
64
    private List exception_vec = new ArrayList();
65
    private List throws_vec = new ArrayList();
65
    private List throws_vec = new ArrayList();
66
    private List code_attrs_vec = new ArrayList();
66
    private List code_attrs_vec = new ArrayList();
67
    private static BCELComparator _cmp = new BCELComparator() {
67
68
    private static final BCELComparator DEFAULT_CMP = new BCELComparator() {
68
69
69
        public boolean equals( Object o1, Object o2 ) {
70
        public boolean equals( Object o1, Object o2 ) {
70
            MethodGen THIS = (MethodGen) o1;
71
            MethodGen THIS = (MethodGen) o1;
Lines 80-85 Link Here
80
        }
81
        }
81
    };
82
    };
82
83
84
    private static ThreadLocal _cmp = new ThreadLocal() {
85
        protected Object initialValue() {
86
            return DEFAULT_CMP;
87
        }
88
    };
83
89
84
    /**
90
    /**
85
     * Declare method. If the method is non-static the constructor
91
     * Declare method. If the method is non-static the constructor
Lines 1050-1056 Link Here
1050
     * @return Comparison strategy object
1056
     * @return Comparison strategy object
1051
     */
1057
     */
1052
    public static BCELComparator getComparator() {
1058
    public static BCELComparator getComparator() {
1053
        return _cmp;
1059
        return (BCELComparator) _cmp.get();
1054
    }
1060
    }
1055
1061
1056
1062
Lines 1058-1064 Link Here
1058
     * @param comparator Comparison strategy object
1064
     * @param comparator Comparison strategy object
1059
     */
1065
     */
1060
    public static void setComparator( BCELComparator comparator ) {
1066
    public static void setComparator( BCELComparator comparator ) {
1061
        _cmp = comparator;
1067
        _cmp.set(comparator);
1062
    }
1068
    }
1063
1069
1064
1070
Lines 1070-1076 Link Here
1070
     * @see java.lang.Object#equals(java.lang.Object)
1076
     * @see java.lang.Object#equals(java.lang.Object)
1071
     */
1077
     */
1072
    public boolean equals( Object obj ) {
1078
    public boolean equals( Object obj ) {
1073
        return _cmp.equals(this, obj);
1079
        return getComparator().equals(this, obj);
1074
    }
1080
    }
1075
1081
1076
1082
Lines 1081-1086 Link Here
1081
     * @see java.lang.Object#hashCode()
1087
     * @see java.lang.Object#hashCode()
1082
     */
1088
     */
1083
    public int hashCode() {
1089
    public int hashCode() {
1084
        return _cmp.hashCode(this);
1090
        return getComparator().hashCode(this);
1085
    }
1091
    }
1086
}
1092
}
(-)v0/src/java/org/apache/bcel/Repository.java (-11 / +16 lines)
Lines 34-53 Link Here
34
 */
34
 */
35
public abstract class Repository {
35
public abstract class Repository {
36
36
37
    private static org.apache.bcel.util.Repository _repository = SyntheticRepository.getInstance();
37
    private static ThreadLocal _repository =
38
        new ThreadLocal() {
39
            protected Object initialValue() {
40
                return SyntheticRepository.getInstance();
41
            }
42
        };
38
43
39
44
40
    /** @return currently used repository instance
45
    /** @return currently used repository instance
41
     */
46
     */
42
    public static org.apache.bcel.util.Repository getRepository() {
47
    public static org.apache.bcel.util.Repository getRepository() {
43
        return _repository;
48
        return (org.apache.bcel.util.Repository) _repository.get();
44
    }
49
    }
45
50
46
51
47
    /** Set repository instance to be used for class loading
52
    /** Set repository instance to be used for class loading
48
     */
53
     */
49
    public static void setRepository( org.apache.bcel.util.Repository rep ) {
54
    public static void setRepository( org.apache.bcel.util.Repository rep ) {
50
        _repository = rep;
55
        _repository.set(rep);
51
    }
56
    }
52
57
53
58
Lines 59-65 Link Here
59
     * parsed correctly
64
     * parsed correctly
60
     */
65
     */
61
    public static JavaClass lookupClass( String class_name ) throws ClassNotFoundException {
66
    public static JavaClass lookupClass( String class_name ) throws ClassNotFoundException {
62
        return _repository.loadClass(class_name);
67
        return getRepository().loadClass(class_name);
63
    }
68
    }
64
69
65
70
Lines 71-77 Link Here
71
     * parsed correctly
76
     * parsed correctly
72
     */
77
     */
73
    public static JavaClass lookupClass( Class clazz ) throws ClassNotFoundException {
78
    public static JavaClass lookupClass( Class clazz ) throws ClassNotFoundException {
74
        return _repository.loadClass(clazz);
79
        return getRepository().loadClass(clazz);
75
    }
80
    }
76
81
77
82
Lines 82-88 Link Here
82
     */
87
     */
83
    public static ClassPath.ClassFile lookupClassFile( String class_name ) {
88
    public static ClassPath.ClassFile lookupClassFile( String class_name ) {
84
        try {
89
        try {
85
            ClassPath path = _repository.getClassPath();
90
            ClassPath path = getRepository().getClassPath();
86
            if (path == null) {
91
            if (path == null) {
87
                return null;
92
                return null;
88
            }
93
            }
Lines 96-102 Link Here
96
    /** Clear the repository.
101
    /** Clear the repository.
97
     */
102
     */
98
    public static void clearCache() {
103
    public static void clearCache() {
99
        _repository.clear();
104
        getRepository().clear();
100
    }
105
    }
101
106
102
107
Lines 106-113 Link Here
106
     * @return old entry in repository
111
     * @return old entry in repository
107
     */
112
     */
108
    public static JavaClass addClass( JavaClass clazz ) {
113
    public static JavaClass addClass( JavaClass clazz ) {
109
        JavaClass old = _repository.findClass(clazz.getClassName());
114
        JavaClass old = getRepository().findClass(clazz.getClassName());
110
        _repository.storeClass(clazz);
115
        getRepository().storeClass(clazz);
111
        return old;
116
        return old;
112
    }
117
    }
113
118
Lines 116-122 Link Here
116
     * Remove class with given (fully qualified) name from repository.
121
     * Remove class with given (fully qualified) name from repository.
117
     */
122
     */
118
    public static void removeClass( String clazz ) {
123
    public static void removeClass( String clazz ) {
119
        _repository.removeClass(_repository.findClass(clazz));
124
        getRepository().removeClass(getRepository().findClass(clazz));
120
    }
125
    }
121
126
122
127
Lines 124-130 Link Here
124
     * Remove given class from repository.
129
     * Remove given class from repository.
125
     */
130
     */
126
    public static void removeClass( JavaClass clazz ) {
131
    public static void removeClass( JavaClass clazz ) {
127
        _repository.removeClass(clazz);
132
        getRepository().removeClass(clazz);
128
    }
133
    }
129
134
130
135
(-)v0/src/java/org/apache/bcel/util/SyntheticRepository.java (-3 / +8 lines)
Lines 48-54 Link Here
48
public class SyntheticRepository implements Repository {
48
public class SyntheticRepository implements Repository {
49
49
50
    private static final String DEFAULT_PATH = ClassPath.getClassPath();
50
    private static final String DEFAULT_PATH = ClassPath.getClassPath();
51
    private static Map _instances = new HashMap(); // CLASSPATH X REPOSITORY
51
    private static ThreadLocal _instances = new ThreadLocal() {
52
        protected Object initialValue() {
53
            return new HashMap();
54
        }
55
    };
52
    private ClassPath _path = null;
56
    private ClassPath _path = null;
53
    private Map _loadedClasses = new HashMap(); // CLASSNAME X JAVACLASS
57
    private Map _loadedClasses = new HashMap(); // CLASSNAME X JAVACLASS
54
58
Lines 64-73 Link Here
64
68
65
69
66
    public static SyntheticRepository getInstance( ClassPath classPath ) {
70
    public static SyntheticRepository getInstance( ClassPath classPath ) {
67
        SyntheticRepository rep = (SyntheticRepository) _instances.get(classPath);
71
        Map map = (Map) _instances.get();
72
        SyntheticRepository rep = (SyntheticRepository) map.get(classPath);
68
        if (rep == null) {
73
        if (rep == null) {
69
            rep = new SyntheticRepository(classPath);
74
            rep = new SyntheticRepository(classPath);
70
            _instances.put(classPath, rep);
75
            map.put(classPath, rep);
71
        }
76
        }
72
        return rep;
77
        return rep;
73
    }
78
    }
(-)v0/src/java/org/apache/bcel/verifier/structurals/ExecutionVisitor.java (-2 / +2 lines)
Lines 715-722 Link Here
715
	public void visitINVOKESPECIAL(INVOKESPECIAL o){
715
	public void visitINVOKESPECIAL(INVOKESPECIAL o){
716
		if (o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME)){
716
		if (o.getMethodName(cpg).equals(Constants.CONSTRUCTOR_NAME)){
717
			UninitializedObjectType t = (UninitializedObjectType) stack().peek(o.getArgumentTypes(cpg).length);
717
			UninitializedObjectType t = (UninitializedObjectType) stack().peek(o.getArgumentTypes(cpg).length);
718
			if (t == Frame._this){	
718
			if (t == Frame._this.get()){	
719
				Frame._this = null;
719
				Frame._this.set(null);
720
			}
720
			}
721
			stack().initializeObject(t);
721
			stack().initializeObject(t);
722
			locals().initializeObject(t);
722
			locals().initializeObject(t);
(-)v0/src/java/org/apache/bcel/verifier/structurals/Frame.java (-1 / +1 lines)
Lines 34-40 Link Here
34
	 * initialized invoking another constructor later.
34
	 * initialized invoking another constructor later.
35
	 * NULL means the instance already *is* initialized.
35
	 * NULL means the instance already *is* initialized.
36
	 */
36
	 */
37
	protected static UninitializedObjectType _this;
37
	protected static ThreadLocal _this = new ThreadLocal();
38
38
39
	/**
39
	/**
40
	 *
40
	 *
(-)v0/src/java/org/apache/bcel/verifier/structurals/InstConstraintVisitor.java (-1 / +2 lines)
Lines 2644-2650 Link Here
2644
	 */
2644
	 */
2645
	public void visitRETURN(RETURN o){
2645
	public void visitRETURN(RETURN o){
2646
		if (mg.getName().equals(Constants.CONSTRUCTOR_NAME)){// If we leave an <init> method
2646
		if (mg.getName().equals(Constants.CONSTRUCTOR_NAME)){// If we leave an <init> method
2647
			if ((Frame._this != null) && (!(mg.getClassName().equals(Type.OBJECT.getClassName()))) ) {
2647
            UninitializedObjectType _this = (UninitializedObjectType) Frame._this.get();
2648
			if ((_this != null) && (!(mg.getClassName().equals(Type.OBJECT.getClassName()))) ) {
2648
				constraintViolated(o, "Leaving a constructor that itself did not call a constructor.");
2649
				constraintViolated(o, "Leaving a constructor that itself did not call a constructor.");
2649
			}
2650
			}
2650
		}
2651
		}
(-)v0/src/java/org/apache/bcel/verifier/structurals/Pass3bVerifier.java (-3 / +4 lines)
Lines 301-311 Link Here
301
				Frame f = new Frame(mg.getMaxLocals(),mg.getMaxStack());
301
				Frame f = new Frame(mg.getMaxLocals(),mg.getMaxStack());
302
				if ( !mg.isStatic() ){
302
				if ( !mg.isStatic() ){
303
					if (mg.getName().equals(Constants.CONSTRUCTOR_NAME)){
303
					if (mg.getName().equals(Constants.CONSTRUCTOR_NAME)){
304
						Frame._this = new UninitializedObjectType(new ObjectType(jc.getClassName()));
304
                        UninitializedObjectType _this = new UninitializedObjectType(new ObjectType(jc.getClassName()));
305
						f.getLocals().set(0, Frame._this);
305
                        Frame._this.set(_this);
306
						f.getLocals().set(0, _this);
306
					}
307
					}
307
					else{
308
					else{
308
						Frame._this = null;
309
                        Frame._this.set(null);
309
						f.getLocals().set(0, new ObjectType(jc.getClassName()));
310
						f.getLocals().set(0, new ObjectType(jc.getClassName()));
310
					}
311
					}
311
				}
312
				}
(-)v0/src/java/org/apache/bcel/verifier/VerifierFactory.java (-10 / +20 lines)
Lines 37-48 Link Here
37
    /**
37
    /**
38
     * The HashMap that holds the data about the already-constructed Verifier instances.
38
     * The HashMap that holds the data about the already-constructed Verifier instances.
39
     */
39
     */
40
    private static Map hashMap = new HashMap();
40
    private static ThreadLocal hashMap = new ThreadLocal() {
41
        protected Object initialValue() {
42
            return new HashMap();
43
        }
44
    };
45
41
    /**
46
    /**
42
     * The VerifierFactoryObserver instances that observe the VerifierFactory.
47
     * The VerifierFactoryObserver instances that observe the VerifierFactory.
43
     */
48
     */
44
    private static List observers = new Vector();
49
    private static ThreadLocal observers = new ThreadLocal() {
45
50
        protected Object initialValue() {
51
            return new Vector();
52
        }
53
    };
46
54
47
    /**
55
    /**
48
     * The VerifierFactory is not instantiable.
56
     * The VerifierFactory is not instantiable.
Lines 57-66 Link Here
57
     * @return the (only) verifier responsible for the class with the given name.
65
     * @return the (only) verifier responsible for the class with the given name.
58
     */
66
     */
59
    public static Verifier getVerifier( String fully_qualified_classname ) {
67
    public static Verifier getVerifier( String fully_qualified_classname ) {
60
        Verifier v = (Verifier) (hashMap.get(fully_qualified_classname));
68
        HashMap map = (HashMap) hashMap.get();
69
        Verifier v = (Verifier) (map.get(fully_qualified_classname));
61
        if (v == null) {
70
        if (v == null) {
62
            v = new Verifier(fully_qualified_classname);
71
            v = new Verifier(fully_qualified_classname);
63
            hashMap.put(fully_qualified_classname, v);
72
            map.put(fully_qualified_classname, v);
64
            notify(fully_qualified_classname);
73
            notify(fully_qualified_classname);
65
        }
74
        }
66
        return v;
75
        return v;
Lines 72-78 Link Here
72
     */
81
     */
73
    private static void notify( String fully_qualified_classname ) {
82
    private static void notify( String fully_qualified_classname ) {
74
        // notify the observers
83
        // notify the observers
75
        Iterator i = observers.iterator();
84
        Iterator i = ((Vector) observers.get()).iterator();
76
        while (i.hasNext()) {
85
        while (i.hasNext()) {
77
            VerifierFactoryObserver vfo = (VerifierFactoryObserver) i.next();
86
            VerifierFactoryObserver vfo = (VerifierFactoryObserver) i.next();
78
            vfo.update(fully_qualified_classname);
87
            vfo.update(fully_qualified_classname);
Lines 88-95 Link Here
88
     * referenced class files.
97
     * referenced class files.
89
     */
98
     */
90
    public static Verifier[] getVerifiers() {
99
    public static Verifier[] getVerifiers() {
91
        Verifier[] vs = new Verifier[hashMap.values().size()];
100
        HashMap map = (HashMap) hashMap.get();
92
        return (Verifier[]) (hashMap.values().toArray(vs)); // Because vs is big enough, vs is used to store the values into and returned!
101
        Verifier[] vs = new Verifier[map.values().size()];
102
        return (Verifier[]) (map.values().toArray(vs)); // Because vs is big enough, vs is used to store the values into and returned!
93
    }
103
    }
94
104
95
105
Lines 97-103 Link Here
97
     * Adds the VerifierFactoryObserver o to the list of observers.
107
     * Adds the VerifierFactoryObserver o to the list of observers.
98
     */
108
     */
99
    public static void attach( VerifierFactoryObserver o ) {
109
    public static void attach( VerifierFactoryObserver o ) {
100
        observers.add(o);
110
        ((Vector) observers.get()).add(o);
101
    }
111
    }
102
112
103
113
Lines 105-110 Link Here
105
     * Removes the VerifierFactoryObserver o from the list of observers.
115
     * Removes the VerifierFactoryObserver o from the list of observers.
106
     */
116
     */
107
    public static void detach( VerifierFactoryObserver o ) {
117
    public static void detach( VerifierFactoryObserver o ) {
108
        observers.remove(o);
118
        ((Vector) observers.get()).remove(o);
109
    }
119
    }
110
}
120
}

Return to bug 42552