title: osx maven running tests Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"
body: <p>I have been trying to run on mac a ready maven project which works under linux. When calling
  <code>mvn clean install</code>
  it runs a portion of the tests and then I am getting the following error:</p>
  
  <p><strong>Exception in thread "main" Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "main"</strong></p>
  
  <p>I have seen many questions about Perm gen error fixed with adding <code>MAVEN_OPTS</code> to environmental variables. Right now I have the following environmental variable on my system:</p>
  
  <p><strong>MAVEN_OPTS="-Xmx4096m -XX:MaxPermSize=4096m"</strong></p>
  
  <p>When calling <code>mvn help:system</code> I can see these options showing up in the configuration.</p>
  
  <p>The project uses Robolectric for testing purposes and (most of the times but not always) prints the following lines before throwing the exception :</p>
  
  <p><strong>[DEBUG] ********************* **GC'ed SdkEnvironment reused!</strong></p>
  
  <p><strong>[ERROR] couldn't load org.robolectric.internal.ParallelUniverse in org.robolectric.bytecode.AsmInstrumentingClassLoader@300abe53</strong></p>
  
  <p>In activity monitor I can see a java process come to life when I start the tests. Its memory usage reaches 1.4~1.5GB before the exception is thrown.  </p>
  
  <p>What else should I do to get it working. 
  Thanks for Your help!</p>
  
  <p><em>EDIT</em>
  after adding the memory options to sure fire plugin : </p>
  
  <blockquote>
  <pre><code>           &lt;plugin&gt;
                 &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                 &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                 &lt;version&gt;2.16&lt;/version&gt;
                 &lt;configuration&gt;
                     &lt;argLine&gt;-Xmx2048m -XX:MaxPermSize=2048m&lt;/argLine&gt;
                 &lt;/configuration&gt;
             &lt;/plugin&gt;
  </code></pre>
  </blockquote>
  
  <p>and running <code>mvn clean install -e -X</code> I got the following stack trace:</p>
  
  <pre><code>[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test (default-test) on project android: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test failed: There was an error in the forked process
  [ERROR] java.lang.OutOfMemoryError: PermGen space
  [ERROR] at java.lang.ClassLoader.defineClass1(Native Method)
  [ERROR] at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
  [ERROR] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
  [ERROR] at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
  [ERROR] at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
  [ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
  [ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
  [ERROR] at java.security.AccessController.doPrivileged(Native Method)
  [ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
  [ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
  [ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
  [ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
  [ERROR] at org.apache.maven.surefire.report.SmartStackTraceParser.getMinimalThrowableMiniMessage(SmartStackTraceParser.java:166)
  [ERROR] at org.apache.maven.surefire.report.SmartStackTraceParser.getString(SmartStackTraceParser.java:151)
  [ERROR] at org.apache.maven.surefire.report.PojoStackTraceWriter.smartTrimmedStackTrace(PojoStackTraceWriter.java:61)
  [ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.encode(ForkingRunListener.java:328)
  [ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.encode(ForkingRunListener.java:312)
  [ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.toString(ForkingRunListener.java:258)
  [ERROR] at org.apache.maven.surefire.booter.ForkingRunListener.testError(ForkingRunListener.java:132)
  [ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:162)
  [ERROR] at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
  [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:200)
  [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
  [ERROR] at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103)
  [ERROR] -&gt; [Help 1]
  </code></pre>
  
  <p>That's with 2GB of memory for surefire and 4GB for maven.</p>