enver 2003/07/24 07:14:47
Modified: src/java/org/apache/bcel/classfile Utility.java
src/java/org/apache/bcel/generic Type.java
Log:
PR: This patch was submitted via the BCEL mailing list; it makes certain
static variables thread safe (although BCEL was never designed with
thread safety in mind, maybe one should check all the framework for
thread safety).
Submitted by: [forgot the name, I'm sorry]
Reviewed by: Enver
Revision Changes Path
1.7 +31 -9 jakarta-bcel/src/java/org/apache/bcel/classfile/Utility.java
Index: Utility.java
===================================================================
RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/classfile/Utility.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Utility.java 23 May 2003 07:55:12 -0000 1.6
+++ Utility.java 24 Jul 2003 14:14:46 -0000 1.7
@@ -67,11 +67,25 @@
* @author <A HREF="mailto:[email protected]">M. Dahm</A>
*/
public abstract class Utility {
- private static int consumed_chars; /* How many chars have been consumed
+
+ private static int unwrap(ThreadLocal tl) {
+ return ((Integer)tl.get()).intValue();
+ }
+
+ private static void wrap(ThreadLocal tl, int value) {
+ tl.set(new Integer(value));
+ }
+
+ private static ThreadLocal consumed_chars = new ThreadLocal() {
+ protected Object initialValue() {
+ return new Integer(0);
+ }
+ };/* How many chars have been consumed
* during parsing in signatureToString().
* Read by methodSignatureToString().
* Set by side effect,but only internally.
*/
+
private static boolean wide=false; /* The `WIDE' instruction is used in the
* byte code to allow 16-bit wide indices
* for local variables. This opcode
@@ -591,7 +605,8 @@
while(signature.charAt(index) != ')') {
vec.add(signatureToString(signature.substring(index), chopit));
- index += consumed_chars; // update position
+ //corrected concurrent private static field acess
+ index += unwrap(consumed_chars); // update position
}
} catch(StringIndexOutOfBoundsException e) { // Should never occur
throw new ClassFormatException("Invalid method signature: " + signature);
@@ -719,7 +734,8 @@
var_index++;
buf.append(", ");
- index += consumed_chars; // update position
+ //corrected concurrent private static field acess
+ index += unwrap(consumed_chars); // update position
}
index++; // update position
@@ -826,7 +842,8 @@
public static final String signatureToString(String signature,
boolean chopit)
{
- consumed_chars = 1; // This is the default, read just one char like `B'
+ //corrected concurrent private static field acess
+ wrap(consumed_chars, 1); // This is the default, read just one char like `B'
try {
switch(signature.charAt(0)) {
@@ -842,8 +859,9 @@
if(index < 0)
throw new ClassFormatException("Invalid signature: " + signature);
-
- consumed_chars = index + 1; // "Lblabla;" `L' and `;' are removed
+
+ //corrected concurrent private static field acess
+ wrap(consumed_chars, index + 1); // "Lblabla;" `L' and `;' are removed
return compactClassName(signature.substring(1, index), chopit);
}
@@ -868,8 +886,12 @@
// The rest of the string denotes a `<field_type>'
type = signatureToString(signature.substring(n), chopit);
-
- Utility.consumed_chars += consumed_chars;
+
+ //corrected concurrent private static field acess
+ //Utility.consumed_chars += consumed_chars; is replaced by:
+ int _temp = unwrap(Utility.consumed_chars)+consumed_chars;
+ wrap(Utility.consumed_chars, _temp);
+
return type + brackets.toString();
}
1.10 +26 -7 jakarta-bcel/src/java/org/apache/bcel/generic/Type.java
Index: Type.java
===================================================================
RCS file: /home/cvs/jakarta-bcel/src/java/org/apache/bcel/generic/Type.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Type.java 23 May 2003 07:55:18 -0000 1.9
+++ Type.java 24 Jul 2003 14:14:47 -0000 1.10
@@ -66,6 +66,7 @@
* @author <A HREF="mailto:[email protected]">M. Dahm</A>
*/
public abstract class Type implements java.io.Serializable {
+
protected byte type;
protected String signature; // signature for the type
@@ -145,7 +146,19 @@
return buf.toString();
}
- private static int consumed_chars=0; // Remember position in string, see getArgumentTypes
+ private static ThreadLocal consumed_chars = new ThreadLocal() {
+ protected Object initialValue() {
+ return new Integer(0);
+ }
+ };//int consumed_chars=0; // Remember position in string, see getArgumentTypes
+
+ private static int unwrap(ThreadLocal tl) {
+ return ((Integer)tl.get()).intValue();
+ }
+
+ private static void wrap(ThreadLocal tl, int value) {
+ tl.set(new Integer(value));
+ }
/**
* Convert signature to a Type object.
@@ -158,7 +171,8 @@
byte type = Utility.typeOfSignature(signature);
if(type <= Constants.T_VOID) {
- consumed_chars = 1;
+ //corrected concurrent private static field acess
+ wrap(consumed_chars, 1);
return BasicType.getType(type);
} else if(type == Constants.T_ARRAY) {
int dim=0;
@@ -169,7 +183,10 @@
// Recurse, but just once, if the signature is ok
Type t = getType(signature.substring(dim));
- consumed_chars += dim; // update counter
+ //corrected concurrent private static field acess
+ // consumed_chars += dim; // update counter - is replaced by
+ int _temp = unwrap(consumed_chars) + dim;
+ wrap(consumed_chars, _temp);
return new ArrayType(t, dim);
} else { // type == T_REFERENCE
@@ -177,8 +194,9 @@
if(index < 0)
throw new ClassFormatException("Invalid signature: " + signature);
-
- consumed_chars = index + 1; // "Lblabla;" `L' and `;' are removed
+
+ //corrected concurrent private static field acess
+ wrap(consumed_chars, index + 1); // "Lblabla;" `L' and `;' are removed
return new ObjectType(signature.substring(1, index).replace('/', '.'));
}
@@ -218,7 +236,8 @@
while(signature.charAt(index) != ')') {
vec.add(getType(signature.substring(index)));
- index += consumed_chars; // update position
+ //corrected concurrent private static field acess
+ index += unwrap(consumed_chars); // update position
}
} catch(StringIndexOutOfBoundsException e) { // Should never occur
throw new ClassFormatException("Invalid method signature: " + signature);
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.