FAQ

This is a compilation of questions that have been asked by JaCoCo users before.

When will feature X be released?

JaCoCo is maintained by volunteers in their free time. Since we cannot guarantee free capacity, we do not commit to particular release dates. Typically, you can expect a couple of releases every year.

In the change log, you can see all features that have been implemented in master branch and will be available with the next release. And in the meantime you can test latest build of master branch (Maven SNAPSHOT) and provide feedback to us.

Does JaCoCo have a plug-in for [Eclipse|Netbeans|Whatever...]?

See this list for current integrations with various tools.

What Java versions are supported by JaCoCo?

JaCoCo supports Java class files from version 1.0 to 22. However the minimum JRE version required by the JaCoCo runtime (e.g. the agent) and the JaCoCo tools is 1.5. Also note that class files under test from version 1.6 and above have to contain valid stackmap frames.

Why do I get the error "Can't add different class with same name"?

For coverage report generation all classes within a group must have unique names. You get this error during report generation if JaCoCo is supplied with multiple different class files with the same name. To fix this remove those duplicate classes or create separate reports or report groups for each version.

Source code lines with exceptions show no coverage. Why?

JaCoCo determines code execution with so called probes. Probes are inserted into the control flow at certain positions. Code is considered as executed when a subsequent probe has been executed. In case of exceptions such a sequence of instructions is aborted somewhere in the middle and the corresponding lines of source code are not marked as covered.

Why does the coverage report not show line coverage figures?

JaCoCo is based on class files analysis. To calculate line coverage class files must contain line number attributes. For this your code must be compiled with debug information.

Why does the coverage report not show highlighted source code?

Make sure the following prerequisites are fulfilled to get source code highlighting in JaCoCo coverage reports:

Why does a class show as not covered although it has been executed?

First make sure execution data has been collected. For this select the Sessions link on the top right corner of the HTML report and check whether the class in question is listed. If it is listed but not linked the class at execution time is a different class file. Make sure you're using the exact same class file at runtime as for report generation. Note that some tools (e.g. EJB containers, mocking frameworks) might modify your class files at runtime. Please see the chapter about class ids for a detailed discussion.

Why are abstract methods not shown in coverage reports?

Abstract methods do not contain code, therefore code coverage cannot be evaluated. Indeed code coverage is recorded for subclasses implementing these methods. The same applies to non-default methods in interfaces.

Can I collect coverage information without stopping the JVM?

Yes, there are three possible ways: The JaCoCo agent can be configured for remote control via TCP/IP sockets. This allows to collect execution data at any point in time from a running JVM. The dump Ant task, the dump Maven goal and the command line interface can be used to request dumps. The remote control feature also allows you to reset execution data.

Alternatively the JaCoCo agent can be configured to expose some functionality via JMX (jmx=true). The bean org.jacoco:type=Runtime provides operations to dump and reset execution data at any point in time.

In addition JaCoCo provides a Java API to directly access the runtime within the JVM executing the tests.

My code uses reflection. Why does it fail when I execute it with JaCoCo?

To collect execution data JaCoCo instruments the classes under test which adds two members to the classes: A private static field $jacocoData and a private static method $jacocoInit(). Both members are marked as synthetic.

Please change your code to ignore synthetic members. This is a good practice anyways as also the Java compiler creates synthetic members in certain situation.

Why do I get an error while instrumenting certain Java classes?

JaCoCo can instrument valid class files only. Class files with syntactical or semantical error will typically lead to exceptions. In certain areas JaCoCo is more restrictive then the JVM: JaCoCo expects valid so-called "stackmap frame" information in class files of version 1.6 or higher. In turn JaCoCo instrumented classes are expected to conform the specification.

Invalid class files are typically created by some frameworks which do not properly adjust stackmap frames when manipulating bytecode.

Does JaCoCo run on the IBM JRE J9 and WebSphere?

It does. To make the JaCoCo agent work please set the VM option -Xshareclasses:none.

Why do I get a NoClassDefFoundError or ClassNotFoundException for class org.jacoco.agent[...]Offline?

If you use offline instrumentation the instrumented classes get a direct dependency on the JaCoCo runtime. Therefore jacocoagent.jar of the same JaCoCo version must be on the classpath and accessible from by the instrumented classes.

Why do I get a StackOverflowError during code coverage analysis?

There are two known reasons for this:

Why do I see classes in the coverage report although I excluded them in the JaCoCo agent configuration?

The includes and excludes options of the JaCoCo agent determine for which classes execution data is collected. Except for technical corner cases these options are normally not required. If you exclude classes, no execution data is collected for them.

Report creation is a separate step where all class files which should show up in the report are explicitly provided. Coverage is determined from the provided execution data. If execution data is missing for a particular class, this class is shown as not covered because the report generator cannot distinguish whether the class was excluded from instrumentation or not executed.

If you want to exclude classes from the report please configure the respective report generation tool accordingly.