Bug 65148 - AntLauncher terminates enclosing VM
Summary: AntLauncher terminates enclosing VM
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.10.9
Hardware: All All
: P2 major (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-02-18 02:03 UTC by Jörn Guy Süß
Modified: 2023-09-18 12:08 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jörn Guy Süß 2021-02-18 02:03:38 UTC
org.apache.tools.ant.launch.Launcher.main() is the recommended way to launch ant from Java as per https://ant.apache.org/manual/running.html#viajava . However,

org.apache.tools.ant.launch.Launcher.main()
calls System.exit(exitCode); (l.114)

This means that integrating this launcher will kill a VM on an error.

This issue cannot be addressed by subclassing as the constructor of Launcher is private, not protected, and is called from main().

This means that any reuser either needs to spawn a VM, or copy the class into a private namespace, shadow it or copy the dispatch method under a different name to extend. None of these alternatives is appealing.

Please ensure that this reuse issue is fixed or deprecate the launcher if it  is not intended for this purpose or cannot be used this way.
Comment 1 Jaikiran Pai 2023-09-17 07:04:16 UTC
I don't have historical knowledge about the org.apache.tools.ant.launch.Launcher class. Looking at the example in the manual, those examples launch the Launcher in a separate JVM (of its own), either using the "java" command or using the "java" Ant task with fork = true. I don't know if Launcher was intended to be used in embedded cases where you use it from within another running Java program.

If it's not intended to be used from within another Java program, then I think we can update the manual to make a note of this behaviour.
Comment 2 Stefan Bodewig 2023-09-18 08:06:02 UTC
I'm afraid my memory of the introduction is rather blurry as well. Not killing the process has not really been a design goal, we wanted to ensure the process exit code actually reflected whether the build was successful. The Launcher class is supposed to be used as the java process' main class.

For an embedded usage of Ant I feel the class is doing to much anyway like spitting diagnostic messages to System streams, modifying system properties or creating custom classloaders. I doubt ideas and other things that run Ant embedded actually use Launcher - more likely they create a Project instance (using ProjectHelper, quite possible a self-provided one) and execute targets on it.

Of course we could add yet another command line argument to Launcher that suppressed System.exit. And we can make the documentation more clear this class is not really intended to be used for embedding Ant. The page is about "running Ant" not embedding it, after all :-).
Comment 3 Jaikiran Pai 2023-09-18 12:08:53 UTC
Thank you for those details, Stefan.

> For an embedded usage of Ant I feel the class is doing to much anyway like spitting diagnostic messages to System streams, modifying system properties or creating custom classloaders.

Given all this, I think just updating the documentation to note that the Launcher class exits the JVM it runs in, should be enough. I can do that sometime this week.