My Java tests stopped working on Linux


#1

The following issue seems to affect only Linux users, but if you are using another platform and ran into the same issue, please let us know!

Note: A new version of OpenJDK (build 191) is now available, and with it, this issue shouldn’t be present anymore. Read below on how to upgrade your OpenJDK on Linux

Your Java tests worked just fine yesterday, but today they fail, with an error message like this?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project demoshop: There are test failures.
[ERROR] 

[ERROR] Please refer to /home/user/dev/repos/RxSeSamples/java/demoshop/target/surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date]-jvmRun[N].dump, [date].dumpstream and [date]-jvmRun[N].dumpstream.
[ERROR] The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd /home/user/dev/repos/RxSeSamples/java/demoshop && /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -jar /home/user/dev/repos/RxSeSamples/java/demoshop/target/surefire/surefirebooter7197313584403359021.jar /home/user/dev/repos/RxSeSamples/java/demoshop/target/surefire 2018-10-31T13-40-14_056-jvmRun1 surefire1521920105769532576tmp surefire_04378496246949909322tmp
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was /bin/sh -c cd /home/user/dev/repos/RxSeSamples/java/demoshop && /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -jar /home/user/dev/repos/RxSeSamples/java/demoshop/target/surefire/surefirebooter7197313584403359021.jar /home/user/dev/repos/RxSeSamples/java/demoshop/target/surefire 2018-10-31T13-40-14_056-jvmRun1 surefire1521920105769532576tmp surefire_04378496246949909322tmp
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
[ERROR] 	at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:671)
[ERROR] 	at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:533)
[ERROR] 	at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:278)
[ERROR] 	at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:244)
[ERROR] 	at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1149)
[ERROR] 	at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:978)
[ERROR] 	at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:854)
[ERROR] 	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
[ERROR] 	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
[ERROR] 	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
[ERROR] 	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
[ERROR] 	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR] 	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR] 	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
[ERROR] 	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR] 	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:309)
[ERROR] 	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:194)
[ERROR] 	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:107)
[ERROR] 	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:955)
[ERROR] 	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)
[ERROR] 	at org.apache.maven.cli.MavenCli.main(MavenCli.java:194)
[ERROR] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] 	at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR] 	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
[ERROR] 	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
[ERROR] 	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
[ERROR] 	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

This may be caused by a bug introduced in the newest OpenJDK version.

How do I know if I am affected?
First, the error message above is a pretty good indicator.
Next, find out which OpenJDK version you have installed, e.g. with the following shell command:

$ java -version

If your output refers to version 1.8.0_181, you may be affected:

OpenJDK version "1.8.0_181"
OpenJDK Runtime Environment (build 1.8.0_181-8u181-b13-1ubuntu0.16.04.1-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)

Any versions lower than this, and presumably higher, should be safe again.

What can I do to fix this?
Before you try anything else, it could be that a fixed version of OpenJDK has been deployed by the time you are reading this article. If so, it can’t hurt to try to update your packages, and see if the issue still appears.

After updating your packages check for your java version. If the OpenJDK version did not update to build _191, you can try to install the Oracle Java JDK, as described in this post. After updating the issue should be fixed!

If that did not work, and you do not have permissions, or do not have the time, to roll back to a previous version, you can try to apply the following workaround.

Go to your pom.xml file and locate the following block:

<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.21.0</version>
  <configuration>
    <suiteXmlFiles>
      <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
    </suiteXmlFiles>
    <reportNameSuffix>${report.name.suffix}</reportNameSuffix>
    <systemPropertyVariables>
      <application.properties>/application.properties</application.properties>
    </systemPropertyVariables>
  </configuration>
</plugin>

Insert the line

<useSystemClassLoader>false</useSystemClassLoader>

So that you end up with the following block instead:

<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <version>2.21.0</version>
  <configuration>
    <useSystemClassLoader>false</useSystemClassLoader>
    <suiteXmlFiles>
      <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
    </suiteXmlFiles>
    <reportNameSuffix>${report.name.suffix}</reportNameSuffix>
    <systemPropertyVariables>
      <application.properties>/application.properties</application.properties>
    </systemPropertyVariables>
  </configuration>
</plugin>

What if I want a permanent fix?
While the above solution should be quite harmless, you may be looking for a more elegant solution.
One option is to roll back your OpenJDK version to a previous version, as this Stackoverflow user has done: https://stackoverflow.com/a/53016532.

Another is to wait for a new OpenJDK version. We will update this thread, when such a version has been released, and it is safe to remove the workaround from your POM-file again.

Conclusion
A change in the newest release of OpenJDK on Linux platforms causes previously working Java tests to fail. For the time being, we recommend the simple workaround, which consists of just adding a single line to the pom.xml file. As the new version of OpenJDK is now available, simply upgrading your JDK should fix the problem.


Release notes v0.19.1
Sample project fail runing on Firefox install on Ubuntu
Java sample project fail on Chrome, FIreFox and Opera
Sample project fails running on Opera installed on Ubuntu