"Forked Java VM exited abnormally" error from junit tests

JavaAntJunitHudson

Java Problem Overview


I have a java junit test that passes when run alone on a development machine. We also have a hudson job which runs all the tests, invoked via ant, on a Mac OS X 10.4 node with Java 1.5. The test was passing in the hudson build until recently but now (with no related code changes) one test fails everytime with the following error:

Error Message

> Forked Java VM exited abnormally. > Please note the time in the report > does not reflect the time until the VM > exit.

Stacktrace

> junit.framework.AssertionFailedError: > Forked Java VM exited abnormally. > Please note the time in the report > does not reflect the time until the VM > exit.

googling shows many others seem to have run into the same problem but there I couldn't find any answer.

Java Solutions


Solution 1 - Java

I faced a similar issue. I ran the junit tests as an ant task. I added the showoutput="yes" ant junit property and ran the ant junit task. It then showed the exception stack trace that caused the forked jvm to exit.

Solution 2 - Java

For me, it was an "java.lang.OutOfMemoryError" in the forked VM (junit task with fork="yes") which made this message appear in the main VM.

The OutOfMemory was visible in the ant log (well, is visible since it's still present).

I use ant 1.7.1, so no hope with upgrading ant.

After putting the same VM parameters in "Run>External tools>External tools>JRE" than in Eclipse.ini (-Xms40m -Xmx512m -XX:MaxPermSize=256M) the problem is solved.

I keep fork to "no" to be sure ant use the parameters.

Solution 3 - Java

I believe I saw this error once when I ended up with multiple versions of junit on my classpath. Might be worth checking out.

Solution 4 - Java

This can occur when an uncaught RuntimeException is thrown. Unfortunately, the junit ant task doesn't output the exception so there isn't an easy way to determine the root cause. You can work around this by running the test case from the command line where the exception will be shown.

java <vm-args> org.junit.runner.JUnitCore <test-class-name>

In my case, an IllegalArgumentException was being thrown.

Solution 5 - Java

I had this problem and it turns out that the process was actually calling System.exit(). However there was also a bug in Ant where this was showing up sometimes. I think Ant 1.7.1 has the bug fixed. So make sure you are running that version.

Solution 6 - Java

Is the VM crashing ? Can you find a dump file (called hs_err_pid*.log) ? If that's the case, the dump file will give you clues to why this is crashing out.

Solution 7 - Java

I had the exact same thing a while back. The problem is that System.exit() is being called somewhere. It can be difficult to find though, as the call could come from either your code or one of the libraries you use.

Solution 8 - Java

I have multiple junit jars in my classpath. one is of ant and another is from WAS. As I removed that the error went away... Ant version that I am using 1.8

Solution 9 - Java

I solved my issue by setting the following environment variable:

Variable: _JAVA_OPTIONS Value: -Xms128m -Xmx512m

Solution 10 - Java

For us, it was actually that we by accident (used a newer version of eclipse) started to use Ant 1.7.x instead of our old ant version which was compatible with our Weblogic 8.1/JDK 1.4.x environment. We fixed this by changing back the Ant Home in Eclipse->Windows->Preferences->Ant->Runtime to our old version of Ant.

Regards Klas

Solution 11 - Java

In my case it's an uncaught exception in a static initializer/method/block inside a class.

Specifically I had one class calling a static method in another class and it was triggering a NumberFormatException.

BTW adding "showoutput=true" to the task in build.xml did not help troubleshoot. Since the static block is one of the first things to run, the JVM was blowing up before it could output anything at all.

Solution 12 - Java

I had this issue too. Changing the junit task from:

<batchtest fork="yes" ... /> 

to

<batchtest fork="no" ... /> 

fixed it for me. I don't fully understand this area of ant though or why doing this would fix it. In my scenario it was an error in "BeforeFirstTest" and I think it barfs because of two ant files in my classpath (which is probably what I ought to fix)

I think the issue is with one of the versions of ant: http://track.pmease.com/browse/QB-500;jsessionid=C1CF6999CBBDB5097A9CFCF4A11AF6C0?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

ETA: I think batchtest="no" actually changes the classpath and hence results in exclusion of my offending ant jar.

Solution 13 - Java

I added TestNG library to the Test Libraries and it fixed the issue.

Solution 14 - Java

In my case, the classpath that my tests were running on exceeded the maximum length of what was allowed by the Operating System for an environment variable (aka the Linux Classpath too long issue).

The solution was to create a pathing jar. Simplified steps:

  1. Use jar (or your IDE) to make a jar of your project, we'll call it MyProject.jar

  2. Make a file called Manifest.txt with the text

> Class-Path: MyProject.jar

  1. Run the jar command line this

> jar cfm PathingJar.jar manifest.txt MyRootPackage/*.class

Then, in your build tool, run your test directive against the pathing jar itself (don't mix-in other classes or jars). Then I was able to get my tests to run without that exception.

Solution 15 - Java

I faced similar issue while running the tests on Jenkins, same tests were passing locally.

I was able resolve the issue by setting log level to WARN

Solution 16 - Java

I faced the same issue. The problem was with byte code generation with mocking the Config class; We changed the import to

import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

and it worked.

Solution 17 - Java

I faced the problem after reinstalling a new version of NetBeans to an external hard disk, upgrading Junit at the same time and using my old workspace.

For me the solution to the same problem was simple:

Just add the JUnit-Library to project properties => Libraries => Compile Tests and Run Tests.

So, in my case, it was just a missing library or a JUnit version conflict.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlbView Question on Stackoverflow
Solution 1 - JavaPrashanthView Answer on Stackoverflow
Solution 2 - JavaTristanView Answer on Stackoverflow
Solution 3 - JavaSharebearView Answer on Stackoverflow
Solution 4 - JavaAlex CView Answer on Stackoverflow
Solution 5 - JavaFrancis Upton IVView Answer on Stackoverflow
Solution 6 - JavaBrian AgnewView Answer on Stackoverflow
Solution 7 - JavatriggerNZView Answer on Stackoverflow
Solution 8 - Javaankit jainView Answer on Stackoverflow
Solution 9 - JavaChikoFerraraView Answer on Stackoverflow
Solution 10 - JavaKlasEView Answer on Stackoverflow
Solution 11 - JavaDan HaynesView Answer on Stackoverflow
Solution 12 - JavaandreaView Answer on Stackoverflow
Solution 13 - JavaEmbarkProView Answer on Stackoverflow
Solution 14 - JavaJason DView Answer on Stackoverflow
Solution 15 - JavaRavi MView Answer on Stackoverflow
Solution 16 - Javauser1164061View Answer on Stackoverflow
Solution 17 - JavaJPSView Answer on Stackoverflow