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

jshell does not run shutdown hooks

XMLWordPrintable

    • b14
    • x86_64
    • windows_10

      A DESCRIPTION OF THE PROBLEM :
      (Affects JDK 21 as well)

      It looks like jshell does not run shutdown hooks when exited with `/exit` or by pressing 'Ctrl' + 'D'.
      This means that if you for example use `File#deleteOnExit` or use jshell to explore a third-party library, the necessary cleanup will not be performed and temporary files remain.

      Side note: If you manually run `System.exit` in jshell, then the shutdown hooks are executed, as desired.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Variant 1:
      1. Start jshell
      2. Run `Runtime.getRuntime().addShutdownHook(new Thread(() -> System.out.println("TEST")));`
      3. Use either `/exit` or press 'Ctrl' + 'D'

      Variant 2:
      1. Start jshell
      2. Run
          ```
          File f = new File("test.txt");
          f.createNewFile();
          f.deleteOnExit();
          ```
      3. Use either `/exit` or press 'Ctrl' + 'D'


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The shutdown hook is executed:
      - Reproducer variant 1: "TEST" is printed to console
      - Reproducer variant 2: The file "test.txt" has been deleted

      ACTUAL -
      The shutdown hook is not executed

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

              Created:
              Updated:
              Resolved: