#53 catch blocks not thread-safe?

closed-fixed
nobody
None
9
2002-04-27
2002-03-28
Anonymous
No

I get some weird exceptions thrown by Beanshell when I
have two or more threads executing in the same catch
block. The following sample code illustrates the problem:

threadBody = new Runnable() {
run() {
try {
Thread.yield();
int val = 1/0;
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
};

numThreads = 3;

for (int i=0; i<numThreads; i++) {
thread = new Thread(threadBody);
thread.start();
}

When I run this, I get the following output:

$ ./bsh-thread-exception-bug.bsh
/ by zero
/ by zero
java.lang.ArrayIndexOutOfBoundsException: 0 >= 0
at java.util.Vector.elementAt(Vector.java:417)
at bsh.CallStack.swap(Unknown Source)
at bsh.BSHBlock.eval(Unknown Source)
at bsh.BSHBlock.eval(Unknown Source)
at bsh.BSHTryStatement.eval(Unknown Source)
at bsh.BSHBlock.eval(Unknown Source)
at bsh.BshMethod.invokeDeclaredMethod(Unknown
Source)
at bsh.XThis$Handler.invoke(Unknown Source)
at $Proxy0.run(Unknown Source)
at java.lang.Thread.run(Thread.java:484)

I've also encountered another exception from a similar
case, which I haven't been able to reliably reproduce:

java.lang.reflect.UndeclaredThrowableException: Attempt
to invoke method: getMessage() on undefined variable or
class name: e: <at unknown location>

(where e is the exception variable name declared in the
catch block).

Details
-------
-beanshell version 1.2b4 (built from the source jar)
-running on WinNT 4.0 SP6
-occurs with both JDK 1.3.1 and JDK 1.4.0

Discussion

  • Pat Niemeyer

    Pat Niemeyer - 2002-04-15
    • priority: 5 --> 9
     
  • Pat Niemeyer

    Pat Niemeyer - 2002-04-15

    Logged In: YES
    user_id=18885

    I understand the problem and will fix it in the next release. Thanks - Pat.

     
  • Pat Niemeyer

    Pat Niemeyer - 2002-04-27
    • status: open --> closed-fixed
     
  • Pat Niemeyer

    Pat Niemeyer - 2002-04-27

    Logged In: YES
    user_id=18885

    Catch blocks were not using the callstack correctly. This has been fixed
    in 1.2b6, along with misc. other bugs related to try/catch variable
    scoping.
    Thanks,
    Pat

     

Log in to post a comment.