Strategy for debugging surefire "The forked VM terminated without saying properly goodbye. VM crash or System.exit called ?" Strategy for debugging surefire "The forked VM terminated without saying properly goodbye. VM crash or System.exit called ?" java java

Strategy for debugging surefire "The forked VM terminated without saying properly goodbye. VM crash or System.exit called ?"


Steps:

(1) Run mvn with the -e and -X options to get more debug information.

(2) Look for "Error" in the output. In my case, when I ran the mvn command, part of the output included:

[ERROR] Command wascmd.exe /X /C "C:\dev\dev-tools\.....

(3) Execute the problematic command directly in the command shell.

In my case, executing

cmd.exe /X /C "C:\dev\dev-tools\....

from the command line resulted in an OutOfMemoryError.


In my case the configuration forkedProcessExitTimeoutInSeconds for the maven-surefire-plugin helps. The default value are since maven-surefire-plugin:2.20.1 30 seconds. My project gots very time consuming test and so the forked JVM chrashes.Configure the plugin in the pom with the following property solves the problem.

<plugin>        <groupId>org.apache.maven.plugins</groupId>        <artifactId>maven-surefire-plugin</artifactId>        <configuration>                <forkedProcessExitTimeoutInSeconds>120</forkedProcessExitTimeoutInSeconds>        </configuration></plugin>


Writing here the strategy that i used to help others who are stuck with this problem.

It is possible to leverage the SecurityManager to throw an exception when System.exit() is called. you can then examine the stack trace to see exactly who called exit(). This is especially useful if the call to exit was made from code hidden inside one of the jars you are depending on and not from your own code.

private static void forbidSystemExitCall() {    final SecurityManager securityManager = new SecurityManager() {        public void checkPermission( Permission permission ) {            if( permission.getName().startsWith("exitVM") ) {                throw new RuntimeException("Something called exit ") ;            }        }    } ;    System.setSecurityManager( securityManager ) ;}