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
(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
- links to
-
Commit(master) openjdk/jdk/8c8b5801
-
Review(master) openjdk/jdk/20599