“Forked Java VM exited abnormally” error from juni

2019-01-17 09:52发布

问题:

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.

回答1:

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.



回答2:

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.



回答3:

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



回答4:

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.



回答5:

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.



回答6:

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.



回答7:

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.



回答8:

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



回答9:

I solved my issue by setting the following environment variable:

Variable: _JAVA_OPTIONS Value: -Xms128m -Xmx512m



回答10:

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



回答11:

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.



回答12:

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.



回答13:

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.



回答14:

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.



回答15:

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.



回答16:

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