"Forked Java VM exited abnormally" error from junit tests
Asked Answered
U

17

53

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.

Unfledged answered 4/12, 2009 at 11:16 Comment(6)
Maybe provide the full stacktrace.Highboy
Pascal: there was no full stacktrace. I still found no answer to this but we've worked around it by moving the hudson job to a different Mac running OS X 10.5 and Java 1.6. The problem does not manifest itself on this setup.Unfledged
That project don't happen to be using JMock, with javaagent parameter declared, right?Hypnotherapy
@Zefi no it's not using JMOckUnfledged
How did it get solved? Which of the following is the correct answer?Chroma
@Chroma I never found a solution, but we no longer run the test on Mac OS so it's no longer a problem for me.Unfledged
H
26

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.

Hexameter answered 29/3, 2013 at 12:59 Comment(0)
E
7

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.

Elizabethelizabethan answered 7/1, 2010 at 16:13 Comment(2)
Another way to allow the forked junit process to access more memory (detailed here: ant.apache.org/manual/Tasks/junit.html) is to use the maxmemory attribute on the junit ant task.Acapulco
Its the case with eclipse, what can we do when running with ANT?Fabric
W
5

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

Waterproof answered 5/12, 2009 at 22:14 Comment(0)
S
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.

Sorption answered 2/5, 2012 at 18:51 Comment(0)
B
3

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.

Bil answered 4/12, 2009 at 11:45 Comment(1)
Thank you. I had this problem when I added a conditional System.exit() to File -> Close instead of just relying on JPanel's dispose(). I'm glad I didn't have to mess around with Ant or with log files.Huerta
P
3

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.

Paddle answered 4/12, 2009 at 13:36 Comment(0)
V
2

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.

Valuator answered 14/12, 2009 at 20:30 Comment(1)
Whoever publishes a library for general use that calls System.exit() needs to be hunted down and shot.Pavonine
C
1

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

Caponize answered 9/11, 2011 at 10:17 Comment(0)
F
0

I solved my issue by setting the following environment variable:

Variable: _JAVA_OPTIONS Value: -Xms128m -Xmx512m

Fao answered 29/4, 2010 at 11:28 Comment(0)
F
0

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

Farandole answered 1/6, 2010 at 8:32 Comment(0)
M
0

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.

Marchant answered 9/5, 2014 at 20:26 Comment(0)
H
0

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.

Hued answered 1/7, 2014 at 17:0 Comment(0)
P
0

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

Photodisintegration answered 25/9, 2017 at 23:57 Comment(0)
P
0

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.

Plante answered 16/10, 2017 at 14:40 Comment(0)
H
0

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

Haplo answered 27/4, 2020 at 10:52 Comment(0)
R
-1

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.

Ritornello answered 14/6, 2012 at 23:12 Comment(0)
R
-1

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.

Ricarda answered 30/7, 2012 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.