JDK-4992454 : (thread) setUncaughtExceptionHandler() doesn't work on main thread
  • Type: Bug
  • Component: tools
  • Sub-Component: launcher
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_8
  • CPU: sparc
  • Submitted: 2004-02-11
  • Updated: 2017-05-16
  • Resolved: 2004-03-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0 b44Fixed
Related Reports
Relates :  
Description
JSR166 introduces a new method for specifying a handler to be invoked
when a thread terminates with an uncaught exception.  However setting
the handler doesn't work on the main thread.  This is because the
launcher checks for an exception on return from the call to main()
and explicitly prints a stack trace using the JNI ExceptionDescribe()
function.  Instead, it should just call the JNI function DetachCurrentThread().

I expect the VM support for this feature to go into build 39 (see bugid 4986764)

The following program demonstrates this bug:


class exception3 extends Thread implements Thread.UncaughtExceptionHandler {

  int _val = 100;

  int c(int arr[]) {
    return arr[5] * 2;
  }

  int b(int arr[]) {
    return c(arr);
  }

  int a(int arr[]) {
    return b(arr);
  }

  int doit (int arr[]) {
    return a(arr);
  }

  public void run() {
    int arr[] = new int[2];
    int res = doit(arr);

    System.out.println(" result = " + res);
  }

  public void uncaughtException(Thread t, Throwable e) {
    if (e instanceof ArrayIndexOutOfBoundsException) {
      System.out.println("Pass.");
    } else {
      System.out.println("Fail: incorrect exception: " + e);
    }
  }

  static public void main(String args[]) {
    exception3 ex3 = new exception3();

    Thread.currentThread().setUncaughtExceptionHandler(ex3);

    ex3.run();
    System.out.println("Fail: exception not thrown.");
  }
}

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta2 FIXED IN: tiger-beta2 INTEGRATED IN: tiger-b44 tiger-beta2
14-06-2004

EVALUATION While the changes to the launcher source are not large; but, they could have a nontrivial compatability impact since they will change the isAlive properties of the main thread, see bug 4833089. The compatibility implications of the fix must be assessed before the fix can be made. ###@###.### 2004-02-13 It would be nice to get this into Tiger. But... ###@###.### 2004-02-13
13-02-2004