Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Cobertura OutOfMemoryError

I am using Maven site:run to generate a cobertura code coverage...

The following is my pom.xml configuration for cobertura:

<reporting>
    ...
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.3</version>
        </plugin>
    </plugins>
</reporting>

However I am getting OutOfMemoryError at the end of the site:run. Please suggest how to get rid of this error. (I have tried all those -Xmx, -XX options...)

Exception in thread "Thread-0" java.lang.OutOfMemoryError: Java heap space
        at sun.reflect.GeneratedSerializationConstructorAccessor74.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
        at java.io.ObjectStreamClass.newInstance(ObjectStreamClass.java:924)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1737)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
        at java.util.HashMap.readObject(HashMap.java:1030)
        at sun.reflect.GeneratedMethodAccessor347.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1947)
        at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:480)
        at net.sourceforge.cobertura.coveragedata.CoverageDataContainer.readObject(CoverageDataContainer.java:373)
        at sun.reflect.GeneratedMethodAccessor348.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
        at java.util.HashMap.readObject(HashMap.java:1030)
        at sun.reflect.GeneratedMethodAccessor347.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:974)
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1849)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753)
like image 608
KrishPrabakar Avatar asked Jan 12 '10 11:01

KrishPrabakar


People also ask

How to resolve OutOfMemoryError in Maven?

As example, if tests are forked (by default), and fails due OutOfMemoryError then try configure plugin which launching them: Show activity on this post. Not only heap memory. You have to increase perm size also to resolve that exception in maven use these variables in environment variable. Show activity on this post.

What is Cobertura Maven plugin?

Cobertura Maven Plugin. The report generated by this plugin is the result of executing the Cobertura tool against your compiled classes to help you determine how well the unit testing and integration testing efforts have been, and can then be used to identify which parts of your Java program are lacking test coverage.

What is OutOfMemoryError in thread main?

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space Usually, this error is thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.

What is the OutOfMemoryError exception in Java?

The OutOfMemoryError Exception in Java looks like this: Usually, this error is thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.


2 Answers

Use this property in your pom.xml :

<project>
...
<build>
...
</build>

<properties>
    <cobertura.maxmem>256M</cobertura.maxmem>
</properties>

</project>
like image 173
Jean-Philippe Briend Avatar answered Nov 16 '22 00:11

Jean-Philippe Briend


Did you try something like export MAVEN_OPTS=-Xmx1024m (Or the highest value that match your machine)?

If you still don't have enough memory to run maven, then I would suggest you try to disable other plugin and exclude some classes from the test coverage to check if it's really a memory issue.

<plugin>
 <groupId>org.codehaus.mojo</groupId>
 <artifactId>cobertura-maven-plugin</artifactId>
 <configuration>
  <instrumentation>
    <ignores>
      <ignore>com.example.boringcode.*</ignore>
    </ignores>
    <excludes>
      <exclude>com/example/dullcode/**/*.class</exclude>
      <exclude>com/example/**/*Test.class</exclude>
    </excludes>
  </instrumentation>
</configuration>

http://mojo.codehaus.org/cobertura-maven-plugin/usage.html

EDIT

Other ideas:

Set the following properties (see the cobertura plugin properties)

-Dmaven.cobertura.report.maxmemory=xxx
-Dmaven.cobertura.instrumentation.maxmemory=xxx

Try to use fork or increase the memory with the following. I'm not sure whether it works for cobertura, but seem to work for junit. Snippet from this page:

<plugin>
...
<configuration>
<forkMode>pertest</forkMode>
</configuration>
</plugin>

or

<plugin>
...
<configuration>
...
<argLine>-Xmx512m -XX:MaxPermSize=256m</argLine> 
</configuration>
</plugin>
like image 35
ewernli Avatar answered Nov 16 '22 01:11

ewernli