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

System.exit(0) kills the launched 3rd party application

    XMLWordPrintable

Details

    • b10
    • x86_64
    • windows_10

    Backports

      Description

        ADDITIONAL SYSTEM INFORMATION :
        Windows 11,
        openjdk version "21.0.2" 2024-01-16 LTS
        OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS)
        OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13-LTS, mixed mode, sharing)


        A DESCRIPTION OF THE PROBLEM :
        Hi there,
        my Java app experienced a very weird regression when switching from JDK
        OpenJDK21U-jdk_x64_windows_hotspot_21.0.1_12
        to
        OpenJDK21U-jdk_x64_windows_hotspot_21.0.2_13

        This small snippet should start a third party software (in this case Notepad++.exe but it's just an example) and after 30 seconds, close the java app that launched it.

        public static void main(String... args) throws IOException {
                String[] cmdToRunUsingArgs = {"cmd.exe", "/C", "C:\\Program Files\\Notepad++\\notepad++.exe"};
                Runtime.getRuntime().exec(cmdToRunUsingArgs);
                Executors.newSingleThreadScheduledExecutor().schedule(() -> {
                    System.exit(0);
                }, 30, TimeUnit.SECONDS);
            }

        It works well with all previous JDK versions but it stopped working from java 21.0.2 and later.

        With java 21.0.1, the program launches the third party app correcly, after 30 seconds, it kills itself by leaving the third app running.
        With java 21.0.2, the program launches the third party app correcly, after 30 seconds, it kills itself AND the third party app.

        This makes even impossible to restart a java app from the app itself.

        REGRESSION : Last worked in version 17.0.10

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the code snippet from a JAR file not in an IDE!

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The program should run a third party software and then close itself leaving the third party software running.
        ACTUAL -
        The program kills both the third party software and itself.

        ---------- BEGIN SOURCE ----------
        public static void main(String... args) throws IOException {
                String[] cmdToRunUsingArgs = {"cmd.exe", "/C", "C:\\Program Files\\Notepad++\\notepad++.exe"};
                Runtime.getRuntime().exec(cmdToRunUsingArgs);
                Executors.newSingleThreadScheduledExecutor().schedule(() -> {
                    System.exit(0);
                }, 30, TimeUnit.SECONDS);
            }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        no workaround found

        FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

                asemenyuk Alexey Semenyuk
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                13 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: