Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8299934

LocalExecutionControl replaces default uncaught exception handler

    XMLWordPrintable

Details

    • generic
    • generic

    Description

      A DESCRIPTION OF THE PROBLEM :
      The invoke method of LocalExecutionControl from JShell replaces Thread.defaultUncaughtExceptionHandler unconditionally, and it also never sets it back.
      This specially affects jdk.jshell API users that wish to use such ExecutionControl, and isn't documented anywhere.
      Instead, given that method starts code in its own ThreadGroup, it should override the ThreadGroup's uncaughtException method, so other code isn't affected.


      ---------- BEGIN SOURCE ----------
      Thread.UncaughtExceptionHandler handler = (e, t) -> {};
      Thread.setDefaultUncaughtExceptionHandler(handler);
      try (JShell jshell = JShell.builder()
      .executionEngine(new LocalExecutionControlProvider(), Map.of())
      .build()) {
      jshell.eval("0");
      }
      System.out.println(handler == Thread.getDefaultUncaughtExceptionHandler());
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Implementing an ExecutionControlProvider that returns an extension of LocalExecutionControl overriding invoke that captures the current one and sets it back after a call to super.invoke.

      The (proper in my opinion) solution is instead, given that method starts code in its own ThreadGroup, to override the ThreadGroup's uncaughtException method.

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              jlahoda Jan Lahoda
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated: