Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An error has occured in JaCoCo report generation

I'm currently trying to add JaCoCo as a dependency on my spring boot maven project to see the code coverage for my unit tests. However, when I run the tests, it fails with error.

 Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.3:report (report) on project test-rest-service: An error has occurred in JaCoCo report generation. Error while creating report: malformed input around byte 2 -> [Help 1]

All tests passes without failure so that isn't a problem.

The dependency for JaCoCo is:

   <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
    </plugin>

The JaCoCo.exec file is produced but I can't open it to generate the report. What am I doing wrong?

like image 800
John Avatar asked Mar 27 '19 15:03

John


3 Answers

At least in my case it was more straightforward. I just had to run mvn clean verify and everything worked again without any issues.

like image 149
s33h Avatar answered Oct 17 '22 02:10

s33h


I've been having a similar problem. I'm writing even though the question is months old as it was very time consuming to figure out and no amount of googling provided me with a straight answer but only to clues I had to piece together myself.


In my case the error happened roughly once every three builds. The error also wasn't always the same as stated in this question: the byte number was changing and sometimes I just got an EOFException instead.

There is a degree of guesswork in my assessment. Here follows the bottomline of my investigation:

  • The error seems to happen as a result of JaCoCo being unable to (fully) write the JaCoCo.exec file, probably due to the corresponding VM being terminated before the write operation completes (or starts). To note that JaCoCo writes said file only when the VM is exiting.
  • If you do multithreading, it could happen because of a thread still running in background causing a timeout in maven-surefire-plugin or maven-failsafe-plugin to trigger. Make sure all your threads run to completion.
  • If the issue is caused by unusual slowness of your machine, you should be able to overcome the problem by setting the forkedProcessExitTimeoutInSeconds option to a value greater than the default 30 seconds (or otherwise greater than what you have currently set) in your maven-surefire-plugin or maven-failsafe-plugin. This was my case, as I was forced to run the build against a very slow and memory-constrained VM.
  • Make sure the forkCount property is greater than 0 in your maven-surefire-plugin or maven-failsafe-plugin and that forkMode is NOT set to never as JaCoCo needs to work on a forked process in order for the file to be written and therefore picked up afterwards.

Example snippet:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.2</version>
    <configuration>
        <forkedProcessExitTimeoutInSeconds>60</forkedProcessExitTimeoutInSeconds>
        <forkCount>1</forkCount>
    </configuration>
</plugin>

References:

  • maven-surefire-plugin -> forkedProcessExitTimeoutInSeconds
  • improperly terminated JaCoco.exec hint
  • JaCoCo and forkCount/forkMode
like image 7
Filippo Possenti Avatar answered Oct 17 '22 02:10

Filippo Possenti


In my case, the error was not very helpful:

Execution jacoco-site of goal org.jacoco:jacoco-maven-plugin:0.8.3:report-aggregate failed: malformed input off : 61255, length : 1: Input length = 1 -> [Help 1]

I had to debug the plugin execution and found that org.jacoco.core.analysis.Analyzer was picking non .class files from target/classes folder that I had there like templates, etc. Some of them were raising a MalformedInputException about incorrect charset. The fix was to include only .class files in plugin configuration:

<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <configuration>
      <includes>
        <include>**/*.class</include>
      </includes>
    </configuration>
</plugin>
like image 4
Aníbal Avatar answered Oct 17 '22 03:10

Aníbal