JDK-8332921 : Ctrl+C does not call shutdown hooks after JLine upgrade
  • Type: Bug
  • Component: tools
  • Sub-Component: jshell
  • Affected Version: 23
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • Submitted: 2024-05-25
  • Updated: 2025-05-16
  • Resolved: 2024-06-06
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.
JDK 21 JDK 23
21.0.8-oracleFixed 23 b26Fixed
Related Reports
Causes :  
Duplicate :  
Relates :  
Description
JDK-8327476 broke handling of Ctrl+C. New version of JLine modifies SIGINT handler and therefore breaks normal processing of Ctrl+C.

To provoke the issue, it's enough to call System.console().

I attached SigIntTest.java that demonstrates the problem.
Before commit 0a4eeeaa, the program printed "Shutdown hook called".
Now, it immediately terminates upon pressing Ctrl+C or sending kill -2 to the process.
Comments
Fix request [21u] I backport this for parity with 21.0.8-oracle. Low risk, simple fix limited to jline usages. Needed resolve. internal/jline tests pass. SAP nightly testing passed.
16-05-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk21u-dev/pull/1779 Date: 2025-05-15 07:11:17 +0000
15-05-2025

Changeset: b3f540d3 Author: Jan Lahoda <jlahoda@openjdk.org> Date: 2024-06-06 04:43:36 +0000 URL: https://git.openjdk.org/jdk/commit/b3f540d354c4a4e2f2199019a2b880a373699560
06-06-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/19559 Date: 2024-06-05 13:09:01 +0000
05-06-2024

FWIW, (some) JLine's Terminal reset signal handlers to default, when a special flag "nativeSignals" is set. In which case the handler that runs the shutdown handlers is removed, and the handlers are not invoked. This has been the case for a long time, the new thing is that this setting was changed from `false` to `true` by default: https://github.com/jline/jline3/pull/971 The fix for this is easy, just explicitly set the flag to `false`. Testing this proves to be somewhat harder, working on that.
04-06-2024

[~apangin] It is unclear to me whether the fix would involve changing code in `jd.internal.le` or in `java.base`. I have changed the component to `tools/jshell` so that the issue appears on the radar screen of the maintainers of jshell (who have upgraded the version of `jline`). The issue may be retargetted back to core-libs/java.io later if it appears the fix should be made in java.base instead.
27-05-2024

Why was this bug reclassified to another category? It has nothing to do with jshell (except that jshell also uses JLine). Note that the attached test case does not use any tools - it simply calls System.console(). In fact, I initially encountered the bug when running usual Spring PetClinic application.
27-05-2024

Seems related: https://github.com/jline/jline3/pull/973
25-05-2024