How has System.exit() wrt to an ANT build changed in JDK 18?

72 views Asked by At
    <target name="myTask" depends="compile">
        <java classname="Main" >
            <classpath>
                <pathelement location="${classes.dir}"/>
            </classpath>
        </java>
        <echo message="myTask completed"/>
    </target>
public class Main {
    public static void main(String[] args) {
        System.out.println("Main from Java!");
        System.exit(0);
    }
}

Executing ant myTask:

Output with JDK 17

     [java] Main from Java!
     [echo] myTask completed

Output with JDK 18

     [java] Main from Java!

The JVM exits with a System.exit() in JDK 18 but was not doing so in JDK 17. Is there a know change introduced in JDK 18 related to this behavior?

1

There are 1 answers

0
Shashank Gupta On BEST ANSWER

It seems Ant updated its behavior from v 1.10.14 due to SecurityManager's removal in JDK 18.

when using Java 18 or higher, if the build executes tasks that call "java.lang.System.exit()" and if those tasks aren't running in a forked VM of their own, then such tasks will now kill the entire Ant build process.

Source: https://downloads.apache.org/ant/RELEASE-NOTES-1.10.14.html