bazel: Bazel 6.0.0 Java 8 Coverage Broken
Description of the bug:
When building with Bazel 6.0.0 and building a Java 8 (compile + runtime, with a local JDK setup) workspace fails to calculate any coverage.
There error I see in the test logs is:
Exception in thread “Thread-0” java.lang.NoSuchMethodError: java.util.Optional.isEmpty()Z at com.google.testing.coverage.JacocoLCOVFormatter$1.getExecPathForEntryName(JacocoLCOVFormatter.java:73) at com.google.testing.coverage.JacocoLCOVFormatter$1.visitBundle(JacocoLCOVFormatter.java:117) at com.google.testing.coverage.JacocoCoverageRunner.createReport(JacocoCoverageRunner.java:156) at com.google.testing.coverage.JacocoCoverageRunner.create(JacocoCoverageRunner.java:132) at com.google.testing.coverage.JacocoCoverageRunner$2.run(JacocoCoverageRunner.java:568)
What’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Execute bazel coverage
on any Java 8 (with a local OpenJDK 8 setup) workspace and look at the coverage files, they are empty.
Which operating system are you running Bazel on?
Mac & Linux
What is the output of bazel info release
?
release 6.0.0
If bazel info release
returns development version
or (@non-git)
, tell us how you built Bazel.
No response
What’s the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD
?
No response
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
Is JacocoLCOVFormatter only Java 11 supported now? Is there any way that maybe we can just change it to use !optional.isPresent()
to make it Java 8 compatible?
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 21 (4 by maintainers)
Commits related to this issue
- Fix Java coverage collection with Java 8 runtime `JacocoCoverageRunner` is run with the target runtime, not the exec runtime, and thus needs to be compatible with a Java 8 runtime. Fixes #17165 Clo... — committed to bazelbuild/bazel by fmeum a year ago
- Fix Java coverage collection with Java 8 runtime (#17491) `JacocoCoverageRunner` is run with the target runtime, not the exec runtime, and thus needs to be compatible with a Java 8 runtime. Fixes ... — committed to bazelbuild/bazel by ShreeM01 a year ago
broken-java8-coverage.zip
Attached is a sample project that recreates the issue following the following steps (assumes you downloaded the zip to an empty dir, also assumes linux OS, modify the less location for other OS’s, you may also have to modify your Java 8 localjdk location in WORKSPACE file):
unzip broken-java8-coverage.zip; bazelisk coverage //...; less bazel-out/k8-fastbuild/testlogs/unit-tests/test.log
You will see that despite the tool java level and runtime being 11, the test runner still fails to calculate coverage due to the Java 9+ added Optional method.