7

So I'm using the JaCoco maven plugin to automatically generate code coverage reports so I can then send them to codecov to display on GitHub. All of a sudden I'm getting a build failure from JaCoco saying "Unknown block type". This wasn't happening the yesterday so I don't know why it happens now. Here is the relevant part of my pom.xml

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

How do I fix this to properly generate coverage reports?

-X trace

[DEBUG] Configuring mojo org.jacoco:jacoco-maven-plugin:0.8.5:report from plugin realm ClassRealm[plugin>org.jacoco:jacoco-maven-plugin:0.8.5, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@55054057]
[DEBUG] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader'.
[DEBUG] Setting property: site.resource.loader.class => 'org.codehaus.plexus.velocity.SiteResourceLoader'.
[DEBUG] Setting property: velocimacro.messages.on => 'false'.
[DEBUG] Setting property: runtime.log.invalid.references => 'false'.
[DEBUG] Setting property: resource.loader => 'classpath,site'.
[DEBUG] Setting property: velocimacro.permissions.allow.inline.to.replace.global => 'true'.
[DEBUG] Setting property: resource.manager.logwhenfound => 'false'.
[DEBUG] *******************************************************************
[DEBUG] Starting Apache Velocity v1.5 (compiled: 2007-02-22 08:52:29)
[DEBUG] RuntimeInstance initializing.
[DEBUG] Default Properties File: org/apache/velocity/runtime/defaults/velocity.properties
[DEBUG] LogSystem has been deprecated. Please use a LogChute implementation.
[DEBUG] Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl)
[DEBUG] ResourceLoader instantiated: org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader
[DEBUG] ResourceLoader instantiated: org.codehaus.plexus.velocity.SiteResourceLoader
[DEBUG] ResourceCache: initialized (class org.apache.velocity.runtime.resource.ResourceCacheImpl)
[DEBUG] Default ResourceManager initialization complete.
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Literal
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Macro
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Parse
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Include
[DEBUG] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach
[DEBUG] Created '20' parsers.
[DEBUG] Velocimacro : initialization starting.
[DEBUG] Velocimacro : allowInline = true : VMs can be defined inline in templates
[DEBUG] Velocimacro : allowInlineToOverride = true : VMs defined inline may replace previous VM definitions
[DEBUG] Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed.
[DEBUG] Velocimacro : autoload off : VM system will not automatically reload global library macros
[DEBUG] Velocimacro : Velocimacro : initialization complete.
[DEBUG] RuntimeInstance successfully initialized.
[DEBUG] Configuring mojo 'org.jacoco:jacoco-maven-plugin:0.8.5:report' with basic configurator -->
[DEBUG]   (f) dataFile = /mnt/a/Documents/school/college/courses/csci420/UMLEditor/target/jacoco.exec
[DEBUG]   (f) outputDirectory = /mnt/a/Documents/school/college/courses/csci420/UMLEditor/target/site/jacoco
[DEBUG]   (f) outputEncoding = UTF-8
[DEBUG]   (f) project = MavenProject: UMLEditor:UMLEditor:0.0.1-SNAPSHOT @ /mnt/a/Documents/school/college/courses/csci420/UMLEditor/pom.xml
[DEBUG]   (f) skip = false
[DEBUG]   (f) sourceEncoding = UTF-8
[DEBUG]   (f) title = UMLEditor
[DEBUG] -- end configuration --
[INFO] Loading execution data file /mnt/a/Documents/school/college/courses/csci420/UMLEditor/target/jacoco.exec
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  36.600 s
[INFO] Finished at: 2020-04-25T04:24:50-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.5:report (report) on project UMLEditor: An error has occurred in JaCoCo report generation.: Error while creating report: Unknown block type 77. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.5:report (report) on project UMLEditor: An error has occurred in JaCoCo report generation.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.MojoExecutionException: An error has occurred in JaCoCo report generation.
    at org.jacoco.maven.AbstractReportMojo.execute (AbstractReportMojo.java:168)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.reporting.MavenReportException: Error while creating report: Unknown block type 77.
    at org.jacoco.maven.AbstractReportMojo.executeReport (AbstractReportMojo.java:184)
    at org.jacoco.maven.AbstractReportMojo.execute (AbstractReportMojo.java:166)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.io.IOException: Unknown block type 77.
    at org.jacoco.core.data.ExecutionDataReader.readBlock (ExecutionDataReader.java:119)
    at org.jacoco.core.data.ExecutionDataReader.read (ExecutionDataReader.java:93)
    at org.jacoco.core.tools.ExecFileLoader.load (ExecFileLoader.java:60)
    at org.jacoco.core.tools.ExecFileLoader.load (ExecFileLoader.java:74)
    at org.jacoco.maven.ReportSupport.loadExecutionData (ReportSupport.java:89)
    at org.jacoco.maven.ReportMojo.loadExecutionData (ReportMojo.java:61)
    at org.jacoco.maven.AbstractReportMojo.executeReport (AbstractReportMojo.java:178)
    at org.jacoco.maven.AbstractReportMojo.execute (AbstractReportMojo.java:166)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:566)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Ryan
  • 727
  • 2
  • 14
  • 31
  • I don't know the answer but take a look at this thread: https://stackoverflow.com/questions/12269558/maven-jacoco-plugin-error. – Andrew Cheong Apr 25 '20 at 07:49
  • @AndrewCheong Just tried that and no luck, even with very large timeout values. Another thing I should mention is that even before I was having this problem, my mvn hangs for quite some time after finishing the last test and doesn't seem to be doing anything. – Ryan Apr 25 '20 at 08:23
  • can you execute the maven command you are using with -X to see more log output? and the error message from jacoco is related to it trying to parse some file? What java version are you running? – wemu Apr 25 '20 at 08:27
  • please post your error stack trace as well for more insight – QuickSilver Apr 25 '20 at 16:49
  • @wemu Edited my post to inlcude the -X trace after the tests finish. The project uses java 1.8 – Ryan Apr 25 '20 at 20:58
  • @QuickSilver Edited post to include trace – Ryan Apr 25 '20 at 20:59
  • well. still hard to tell what happened. either some dependency got upgraded or did you change how you run tests? To try to get closer I would remove some tests until the error is gone and then re-add them "one by one". Maybe that gives a hint where it is coming from. Some of the libs in that stacktrace are very old. can you run "mvn -v" once? – wemu Apr 25 '20 at 21:38
  • @wemu So "mvn -v" returns 3.6.3. I also believe I have located the troublesome test file as when I exclude it everything runs fine and it even stops hanging. I just don't understand what would be wrong in that file that would cause a hang (there are no loops, the only "files" being done are modifying the default System.out/err streams to a separate print writer) given that most of it is string manipulation. I then went through the tests and disabled each one at a time and it would only work once all were disabled, meaning something may be wrong with the file it is testing? – Ryan Apr 25 '20 at 22:30
  • But what would the tested file be doing that causes a hang in the mvn test? It doesn't hang at all when I do it in eclipse – Ryan Apr 25 '20 at 22:31
  • "modifying the default System.out/err streams to a separate print writer" sounds a bit weird. what sort of test do you write? Without the test class it will be hard to tell. It could be just some sort or test order issue. IDEs often execute tests in a different order than CLIs - as there is no guarantee anyway for test ordering it should not matter as it may change any time.Are other tests doing a similar thing? But it seems the troublesome test class is found? So are there issues in test setup or improper teardown? – wemu Apr 26 '20 at 16:07
  • @wemu I was writing tests that check the output. I just now changed my code to allow myself to inject a PrintWriter instead of setting System.out but I am still getting the issue. Except now I get an "EOFException" from JaCoco. – Ryan Apr 26 '20 at 20:59
  • @wemu Ah nevermind, I found the solution. I had a Scanner reading from System.in, and even though I was never using this Scanner in my tests I did close the scanner at the end of my tests. Once I removed that close statement it no longer hangs and the problem goes away. Thanks for all your help! – Ryan Apr 26 '20 at 21:15

2 Answers2

8

I was having quite a similar message, performing an mvn install yielding a JaCoCo error (the difference being a Unknown block type 45 error instead of Unknown block type 77 like in the original question):

[ERROR] Failed to execute goal org.jacoco:jacoco-maven-plugin:0.8.5:report (report) on project UMLEditor: An error has occurred in JaCoCo report generation.: Error while creating report: Unknown block type 45. -> [Help 1]

I got rid of this error simply by performing an mvn clean and relaunching the build.

potame
  • 7,597
  • 4
  • 26
  • 33
7

Unknown block type

during the execution of org.jacoco:jacoco-maven-plugin:0.8.5:report indicates corrupted jacoco.exec file.

This file is produced by JaCoCo agent at the termination of JVM with tests using JVM shutdown hook.

Corruption of file typically happens when JVM with tests is hard-killed instead of proper graceful successful termination.

my mvn hangs for quite some time after finishing the last test and doesn't seem to be doing anything

is IMO a confirmation that JVM with tests is not terminated gracefully, because this typically indicates that maven-surefire-plugin waits for termination of your tests for some time and then kills JVM - see similar issue https://github.com/jacoco/jacoco/issues/1042

All in all, please fix your code/tests - JVM with tests should terminate gracefully.


I also believe I have located the troublesome test file as when I exclude it everything runs fine and it even stops hanging. I just don't understand what would be wrong in that file that would cause a hang (there are no loops, the only "files" being done are modifying the default System.out/err streams to a separate print writer) given that most of it is string manipulation.

Quoting http://maven.apache.org/surefire/maven-surefire-plugin/faq.html for maven-surefire-plugin version 3.0.0-M4:

It would be even worse if you override the Java stream by System.setOut because the stream is also supposed to be corrupted but the Maven will never see the tests finished and build may hang.

Godin
  • 9,801
  • 2
  • 39
  • 76
  • 1
    So possibly dumb question but I'm new to this stuff, how can I make sure my tests are terminating gracefully? When I run them in Eclipse I have no issues and everything terminates immediately after completion. – Ryan Apr 25 '20 at 21:00
  • So I've actually narrowed down the test file causing the problem, but I don't understand what would be causing the issue in that file since I don't see the problem in eclipse. – Ryan Apr 25 '20 at 22:32
  • @user13403586 First of all - how somebody can blindly guess what is wrong in your code in absence of https://stackoverflow.com/help/minimal-reproducible-example ? Nevertheless see updated answer based on your other comments. – Godin Apr 26 '20 at 08:16
  • 1
    So I have since changed the tests to no longer set System.out and instead I just pass in a PrintWriter to the methods that print, but I am now getting an "EOFException". I make sure to close all streams. I was more just asking what general cases may cause this for me to look out for? – Ryan Apr 26 '20 at 21:03
  • 2
    Ah nevermind, I found the solution. I had a Scanner reading from System.in, and even though I was never using this Scanner in my tests I did close the scanner at the end of my tests. Once I removed that close statement it no longer hangs and the problem goes away. Thanks for all your help! – Ryan Apr 26 '20 at 21:14