Cobertura: Error reading file cobertura.ser: null java.io.EOFException: null

1.7k views Asked by At

I have been working on Cobertura for couple months and recently I'm getting an error saying that "Error Reading .ser file" from particular target location.Does anyone has idea why am I getting the below error:

Cobertura maven plugin version:2.7

Java version : 1.8

    [INFO] Cobertura 2.1.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[ERROR] Cobertura: Error reading file C:\view\
xyz\target\cobertura\cobertura.s
er: null
java.io.EOFException: null
        at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputSt
ream.java:2626) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1321) ~[
na:1.8.0_102]
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:20
18) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1942)
 ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
808) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353) ~[
na:1.8.0_102]
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373) ~[na
:1.8.0_102]
        at java.util.HashMap.readObject(HashMap.java:1404) ~[na:1.8.0_102]
        at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source) ~[na:na]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43) ~[na:1.8.0_102]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_102]
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:105
8) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1909)
 ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
808) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353) ~[
na:1.8.0_102]
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:20
18) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:50
3) ~[na:1.8.0_102]
        at net.sourceforge.cobertura.coveragedata.CoverageDataContainer.readObje
ct(CoverageDataContainer.java:321) ~[cobertura-2.1.1.jar:2.1.1]
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) ~[na:na]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43) ~[na:1.8.0_102]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_102]
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:105
8) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1909)
 ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
808) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353) ~[
na:1.8.0_102]
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373) ~[na
:1.8.0_102]
        at java.util.HashMap.readObject(HashMap.java:1404) ~[na:1.8.0_102]
        at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source) ~[na:na]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43) ~[na:1.8.0_102]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_102]
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:105
8) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1909)
 ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
808) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353) ~[
na:1.8.0_102]
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:20
18) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:50
3) ~[na:1.8.0_102]
        at net.sourceforge.cobertura.coveragedata.CoverageDataContainer.readObje
ct(CoverageDataContainer.java:321) ~[cobertura-2.1.1.jar:2.1.1]
        at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) ~[na:na]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43) ~[na:1.8.0_102]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_102]
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:105
8) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1909)
 ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
808) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353) ~[
na:1.8.0_102]
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373) ~[na
:1.8.0_102]
        at java.util.HashMap.readObject(HashMap.java:1404) ~[na:1.8.0_102]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.
0_102]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62) ~[na:1.8.0_102]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43) ~[na:1.8.0_102]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_102]
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:105
8) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1909)
 ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
808) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353) ~[
na:1.8.0_102]
        at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:20
18) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.defaultReadObject(ObjectInputStream.java:50
3) ~[na:1.8.0_102]
        at net.sourceforge.cobertura.coveragedata.CoverageDataContainer.readObje
ct(CoverageDataContainer.java:321) ~[cobertura-2.1.1.jar:2.1.1]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.
0_102]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:62) ~[na:1.8.0_102]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43) ~[na:1.8.0_102]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_102]
        at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:105
8) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1909)
 ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1
808) ~[na:1.8.0_102]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353) ~[
na:1.8.0_102]
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373) ~[na
:1.8.0_102]
        at net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler.loadCo
verageData(CoverageDataFileHandler.java:85) ~[cobertura-2.1.1.jar:2.1.1]
        at net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler.loadCo
verageData(CoverageDataFileHandler.java:62) ~[cobertura-2.1.1.jar:2.1.1]
        at net.sourceforge.cobertura.dsl.Cobertura.getProjectDataInstance(Cobert
ura.java:146) [cobertura-2.1.1.jar:2.1.1]
        at net.sourceforge.cobertura.dsl.Cobertura.report(Cobertura.java:122) [c
obertura-2.1.1.jar:2.1.1]
        at net.sourceforge.cobertura.reporting.ReportMain.parseArgumentsAndRepor
t(ReportMain.java:91) [cobertura-2.1.1.jar:2.1.1]
        at net.sourceforge.cobertura.reporting.ReportMain.generateReport(ReportM
ain.java:141) [cobertura-2.1.1.jar:2.1.1]
        at net.sourceforge.cobertura.reporting.ReportMain.main(ReportMain.java:1
51) [cobertura-2.1.1.jar:2.1.1]
Report time: 1031ms

Thanks in advance.

3

There are 3 answers

0
Praveen Kumar Mekala On

Usually .ser files gets locked only when you don't have enough memory that has been allocated for cobertura to generate the report. The solution should be

1) Delete all unnecessary test class files from src/test/java and run cobertura or

2) Increase the memory size of cobertura, something like below

    <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>cobertura-maven-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <quiet>true</quiet>
                <cobertura.maxmem>1024m</cobertura.maxmem>
                <instrumentation>
                    <excludes>
                        <exclude>com/homepage/helper/ABC.class</exclude>

                    </excludes>
                    <ignores>
                        <!-- <ignore>com..homepage..helper.ABC</ignore> -->
                    </ignores>
                    <maxmem>1024m</maxmem>
                </instrumentation>
                <argLine>-Xms512m -Xmx2048m -XX:MaxPermSize=1024m</argLine>
                <!-- <argLine>-Xmx2048m</argLine> -->
            </configuration>
            <executions>
                <execution>
                    <id>clean</id>
                    <phase>pre-site</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
                <execution>
                    <id>instrument</id>
                    <phase>site</phase>
                    <goals>
                        <goal>instrument</goal>
                        <goal>cobertura</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

In pom.xml just change the cobertura.maxmem size to whatever we want and We have option like ignoring few classes while generating report also.

3) And there is one more possibility that your sure-fire plugin version is not supported. If above two solutions are not working then try updating sure-fire version like below (maven-surefire-plugin should be 2.12):

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.12</version>
            <dependencies>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit47</artifactId>
                    <version>2.17</version>
                </dependency>
            </dependencies>             
            <configuration>                     
                     <groups>${testcase.include}</groups>
                     <excludedGroups>${testcase.exclude}</excludedGroups>
            </configuration>

        </plugin>

Hope it's useful.

1
Bradley D On

Tried updating the memory as per above and that did not work for us. However, found a 'solution' (or remedy at least) inadvertently via another way:

We had about 60 test classes that were decorated with the class level annotation

@RunWith(PowerMockRunner.class)

Coincidentally, since these classes were not showing coverage in our local environments (which actually use EclEmma for code coverage - which is the same as JaCoCo - KNOWN PROBLEM), I tried converting the annotation...

@RunWith(PowerMockRunner.class)

to

@RunWith(MockitoJUnitRunner.class)

and was able to convert about 30 of the 60 we had. While we were not able to convert all of them, since some are tied to PowerMock features in the tests, such as allowing testing of static methods. But converting the annotation from PowerMockRunner to MockitoJUnitRunner still somehow remedied the above problem of Cobertura erroring out as per the above error. I still am unable to give a substantive answer as to why exactly this would be, because Cobertura does show coverage for classes with @RunWith(PowerMockRunner.class). But I will update this post once I know.

0
Gergo On

Check if next to the file there is a cobertura.ser.lock file too. If it there then problem is that cobertura writes out the coverage data at the end of the run when the VM is shutting down. Based on how many classes you had it can take a while. Surefire plugin will kill the VM if it is not shutting down within 30 seconds by default sometimes in the middle of the process leaving the file locked. You can solve the problem by using surefire 2.20 or above and adding a bigger value of shutdown timeout(forkedProcessExitTimeoutInSeconds). Here is an example:

 <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.20</version>
    <configuration>
         <forkedProcessExitTimeoutInSeconds>120</forkedProcessExitTimeoutInSeconds>
    </configuration>
 </plugin>