Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel coverage with --combined_report=lcov fails #6450

Closed
chris-rice-lr opened this issue Oct 19, 2018 · 27 comments
Closed

Bazel coverage with --combined_report=lcov fails #6450

chris-rice-lr opened this issue Oct 19, 2018 · 27 comments
Assignees
Labels
coverage P2 We'll consider working on this in future. (Assignee optional) team-Rules-Server Issues for serverside rules included with Bazel type: bug

Comments

@chris-rice-lr
Copy link

Description of the problem / feature request:

Running bazel coverage --combined_report=lcov //... results in a NullPointerException

> bazel coverage --combined_report=lcov //...
INFO: Using default value for --instrumentation_filter: "//src/main/java/com/chris[/:]".
INFO: Override the above default with --instrumentation_filter
Internal error thrown during build. Printing stack trace: java.lang.NullPointerException
	at com.google.devtools.build.lib.bazel.coverage.BazelCoverageReportModule$1.getArgs(BazelCoverageReportModule.java:108)
	at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder.generateCoverageReportAction(CoverageReportActionBuilder.java:244)
	at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder.createCoverageActionsWrapper(CoverageReportActionBuilder.java:192)
	at com.google.devtools.build.lib.bazel.coverage.BazelCoverageReportModule$1.createCoverageReportActionsWrapper(BazelCoverageReportModule.java:93)
	at com.google.devtools.build.lib.analysis.BuildView.createResult(BuildView.java:436)

It appears that the default value of --coverage_report_generator causes this. Running it with --coverage_report_generator="@bazel_tools//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:Main" works; though it should be pointed out that there are some SEVERE logs.

> bazel coverage --combined_report=lcov --coverage_report_generator="@bazel_tools//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:Main" //...
INFO: Using default value for --instrumentation_filter: "//src/main/java/com/chris[/:]".
INFO: Override the above default with --instrumentation_filter
INFO: Analysed 5 targets (23 packages loaded).
INFO: Found 3 targets and 2 test targets...
INFO: LCOV coverage report is located at /home/chris.rice/.cache/bazel/_bazel_chris.rice/1baebf64cb080dc7a8e39a79a89b8741/execroot/__main__/bazel-out/_coverage/_coverage_report.dat
 and execpath is bazel-out/_coverage/_coverage_report.dat
INFO: From CoverageReport _coverage/_coverage_report.dat:
Oct 19, 2018 8:57:48 AM com.google.devtools.lcovmerger.Main getTracefiles
INFO: Found 2 tracefiles.
Oct 19, 2018 8:57:48 AM com.google.devtools.lcovmerger.Main parseFiles
SEVERE: Parsing file bazel-out/k8-fastbuild/testlogs/src/test/java/com/chris/foo/FooTest/coverage.dat
Oct 19, 2018 8:57:48 AM com.google.devtools.lcovmerger.Main parseFiles
SEVERE: Parsing file bazel-out/k8-fastbuild/testlogs/src/test/java/com/chris/hello/HelloWorldTest/coverage.dat
Oct 19, 2018 8:57:48 AM com.google.devtools.lcovmerger.Main getGcovInfoFiles
SEVERE: No gcov info file found.
INFO: Elapsed time: 6.037s, Critical Path: 5.47s
INFO: 15 processes: 10 linux-sandbox, 5 worker.
INFO: Build completed successfully, 35 total actions
//src/test/java/com/chris/foo:FooTest                                    PASSED in 0.7s
  /home/chris.rice/.cache/bazel/_bazel_chris.rice/1baebf64cb080dc7a8e39a79a89b8741/execroot/__main__/bazel-out/k8-fastbuild/testlogs/src/test/java/com/chris/foo/FooTest/coverage.dat
//src/test/java/com/chris/hello:HelloWorldTest                           PASSED in 0.6s
  /home/chris.rice/.cache/bazel/_bazel_chris.rice/1baebf64cb080dc7a8e39a79a89b8741/execroot/__main__/bazel-out/k8-fastbuild/testlogs/src/test/java/com/chris/hello/HelloWorldTest/coverage.dat

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Clone this repo: https://github.com/chris-rice-lr/bazel_combined_report_repro and run

bazel coverage --combined_report=lcov //...

Running

bazel coverage --combined_report=lcov --coverage_report_generator="@bazel_tools//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:Main" //...

will result in a single .dat file as expected

What operating system are you running Bazel on?

Fedora 28

What's the output of bazel info release?

> bazel info release
Starting local Bazel server and connecting to it...
release 0.18.0- (@non-git)

If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.

I used the COPR repo: https://copr.fedorainfracloud.org/coprs/vbatts/bazel/

What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?

> git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
git@github.com:chris-rice-lr/bazel_combined_report_repro.git
3b2b00c761c46fe8ea6a86deed47c8f10607ded3
3b2b00c761c46fe8ea6a86deed47c8f10607ded3

Have you found anything relevant by searching the web?

This thread helped. It showed that running with --coverage_report_generator set correctly made it work. https://groups.google.com/forum/#!searchin/bazel-discuss/combined_report%7Csort:date/bazel-discuss/itJkJ2T4mWw/qNKGEk_uFAAJ

@aiuto aiuto added team-Rules-Java Issues for Java rules untriaged labels Oct 23, 2018
@fahhem
Copy link
Contributor

fahhem commented Nov 7, 2018

I get this as well, almost filed another bug because this isn't marked as a bug.

My traceback is the same. Here's my bug details:

What operating system are you running Bazel on?

Ubuntu 16.04.4 LTS (inside a docker, inside Ubuntu 16.04.5 LTS)

What's the output of bazel info release?

release 0.19.0

Other info

We've been using bazel inside this docker (with updates along the way) mostly-happily for a year now, so the docker stuff isn't the cause.

@fahhem
Copy link
Contributor

fahhem commented Nov 7, 2018

I get this traceback after setting the right flag:

--coverage_report_generator="@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main"

Internal error thrown during build. Printing stack trace: java.lang.RuntimeException: Unrecoverable error while evaluating node 'ActionLookupData{actionLookupKey=com.google.devtools.build.lib.skyframe.CoverageReportValue$CoverageReportKey@737c7335, actionIndex=1}' (requested by nodes 'File:[[<execution_root>]bazel-
out]_coverage/_coverage_report.dat')
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:499)
        at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:368)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: null for File:[[<execution_root>]bazel-out/host/bin]external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main.jar
        at com.google.common.base.Preconditions.checkState(Preconditions.java:588)
        at com.google.devtools.build.lib.skyframe.PerActionFileCache.getMetadata(PerActionFileCache.java:53)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$DelegatingPairFileCache.getMetadata(SkyframeActionExecutor.java:1330)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.getInputMetadata(TreeNodeRepository.java:500)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:330)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildParentNode(TreeNodeRepository.java:348)
        at com.google.devtools.build.lib.remote.TreeNodeRepository.buildFromActionInputs(TreeNodeRepository.java:285)
        at com.google.devtools.build.lib.remote.RemoteSpawnCache.lookup(RemoteSpawnCache.java:100)
        at com.google.devtools.build.lib.exec.AbstractSpawnStrategy.exec(AbstractSpawnStrategy.java:101)
        at com.google.devtools.build.lib.exec.AbstractSpawnStrategy.exec(AbstractSpawnStrategy.java:75)
        at com.google.devtools.build.lib.exec.SpawnActionContextMaps$ProxySpawnActionContext.exec(SpawnActionContextMaps.java:362)
        at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder$CoverageReportAction.execute(CoverageReportActionBuilder.java:125)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.executeActionTask(SkyframeActionExecutor.java:1001)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.prepareScheduleExecuteAndCompleteAction(SkyframeActionExecutor.java:930)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.access$800(SkyframeActionExecutor.java:121)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$ActionRunner.call(SkyframeActionExecutor.java:770)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$ActionRunner.call(SkyframeActionExecutor.java:725)
        at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.executeAction(SkyframeActionExecutor.java:478)
        at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.checkCacheAndExecuteIfNeeded(ActionExecutionFunction.java:519)
        at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.compute(ActionExecutionFunction.java:216)
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:422)
        ... 4 more

@lukaszrek
Copy link

I have the same problem as @fahhem getting exception

Caused by: java.lang.IllegalStateException: null for File:[[<execution_root>]bazel-out/host/bin]external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main.jar

I am running command:

bazel coverage --experimental_java_coverage --combined_report=lcov --coverage_report_generator @bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main //...

I don't get this exception when running coverage on Ubuntu 18.04.1 LTS
It occurs on CentOS Linux release 7.5.1804 (Core)

Ls returns same on both Ubuntu and CentOS:

> ls -l bazel-out/host/bin/external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator
Main

Using bazel 0.20.0

Please let me know if I can provide more debug information.

@brendandouglas
Copy link
Contributor

Is this actually specific to java rules -- perhaps the 'team-Rules-Java' tag should be removed?

'bazel coverage' with the '--combined_report=lcov' appears to be broken.

Still happening in bazel 0.21. Something that might be relevant: if I use --coverage_report_generator=@bazel_tools//tools/test:coverage_report_generator it fails with the original NPE, but specifying --coverage_report_generator=@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main fails later, when trying to combine output .dat files.

However @bazel_tools//tools/test:coverage_report_generator is just:

filegroup(
    name = "coverage_report_generator",
    srcs = ["@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main"],
)

@ensonic
Copy link
Contributor

ensonic commented Feb 27, 2019

I can second that this does not seem to be related to java. I get this for all kind of languages, eg:

bazel coverage --combined_report=lcov //src/go/... 
INFO: Using default value for --instrumentation_filter: "//src/go/cmd[/:],//src/go/pkg[/:]".
INFO: Override the above default with --instrumentation_filter
DEBUG: /usr/local/google/home/ensonic/.cache/bazel/_bazel_ensonic/556f802681b2087c6d9a6bcc3d0d954b/external/bazel_skylib/lib.bzl:30:1: WARNING: lib.bzl is deprecated and will go away in the future, please directly load the bzl file(s) of the module(s) needed as it is more efficient.
Internal error thrown during build. Printing stack trace: java.lang.NullPointerException
	at com.google.devtools.build.lib.bazel.coverage.BazelCoverageReportModule$1.getArgs(BazelCoverageReportModule.java:112)
	at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder.generateCoverageReportAction(CoverageReportActionBuilder.java:244)
	at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder.createCoverageActionsWrapper(CoverageReportActionBuilder.java:192)
	at com.google.devtools.build.lib.bazel.coverage.BazelCoverageReportModule$1.createCoverageReportActionsWrapper(BazelCoverageReportModule.java:95)
	at com.google.devtools.build.lib.analysis.BuildView.createResult(BuildView.java:475)
	at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:418)
	at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:209)
	at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:118)
	at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:146)
	at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:273)
       ...

@lberki lberki added P2 We'll consider working on this in future. (Assignee optional) coverage and removed untriaged labels Mar 13, 2019
@sgammon
Copy link

sgammon commented Jul 21, 2019

is it true that, to this day, Java coverage doesn't work in Bazel? or am i missing some fix/change?

this bug has been open since 2018. is there anything the community can do to help move it along?

EDIT: or is it just lcov output?

@iirina
Copy link
Contributor

iirina commented Jul 25, 2019

It works, you just have to specify another flag on the command line when using --combined_report=lcov:

--coverage_report_generator=@bazel_tools//tools/test/LcovMerger/java/com/google/devtools/lcovmerger:Main

The default value of the --coverage_report_generator flag is broken and we didn't get to fixing it. It should be an easy change though, PRs are always welcome. :)

Note: this issue is about getting a combined report with coverage data from all test runs. If --combined_report is not specified Bazel creates a coverage report for each test run and the user has to merge them themselves or work with the reports as they are.

@bogatuadrian
Copy link

bogatuadrian commented Jul 31, 2019

@iirina LcovMerger seems to be missing from https://github.com/bazelbuild/bazel/tree/master/tools/test. Am I looking in the wrong place? If so, where should I find tools/test/LcovMerger/java/com/google/devtools/lcovmerger? Thanks.

EDIT: OK, I found it at the 0.18.1 tag, but I see that in newer versions of Bazel this has been renamed to CoverageOutputGenerator (8f4786b). I am using 0.28.1. I will leave this here if other people run into this.

@codesuki
Copy link

codesuki commented Aug 5, 2019

@iirina
Trying to generate the coverage report for a go project with this cmdline

bazel coverage --combined_report=lcov --coverage_report_generator=@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main //pkg/...

results in a runtime exception:

Internal error thrown during build. Printing stack trace: java.lang.RuntimeException: Unrecoverable error while evaluating node 'ActionLookupData{actionLookupKey=com.google.devtools.build.lib.skyframe.CoverageReportValue$CoverageReportKey@46c9a92e, actionIndex=1}' (requested by nodes )
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:528)
        at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:399)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: null for File:[[<execution_root>]bazel-out/host/bin]external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main.jar
        at com.google.devtools.build.lib.skyframe.ActionMetadataHandler.getMetadata(ActionMetadataHandler.java:212)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$DelegatingPairFileCache.getMetadata(SkyframeActionExecutor.java:1537)
        at com.google.devtools.build.lib.remote.merkletree.InputTree.build(InputTree.java:294)
        at com.google.devtools.build.lib.remote.merkletree.InputTree.build(InputTree.java:255)
        at com.google.devtools.build.lib.remote.merkletree.MerkleTree.build(MerkleTree.java:94)
        at com.google.devtools.build.lib.remote.RemoteSpawnCache.lookup(RemoteSpawnCache.java:129)
        at com.google.devtools.build.lib.exec.AbstractSpawnStrategy.exec(AbstractSpawnStrategy.java:118)
        at com.google.devtools.build.lib.exec.AbstractSpawnStrategy.exec(AbstractSpawnStrategy.java:88)
        at com.google.devtools.build.lib.exec.ProxySpawnActionContext.exec(ProxySpawnActionContext.java:52)
        at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder$CoverageReportAction.execute(CoverageReportActionBuilder.java:126)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$4.execute(SkyframeActionExecutor.java:841)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$ActionRunner.continueAction(SkyframeActionExecutor.java:975)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$ActionRunner.run(SkyframeActionExecutor.java:947)
        at com.google.devtools.build.lib.skyframe.ActionExecutionState.runStateMachine(ActionExecutionState.java:116)
        at com.google.devtools.build.lib.skyframe.ActionExecutionState.getResultOrDependOnFuture(ActionExecutionState.java:77)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.executeAction(SkyframeActionExecutor.java:571)
        at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.checkCacheAndExecuteIfNeeded(ActionExecutionFunction.java:742)
        at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.compute(ActionExecutionFunction.java:260)
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:451)
        ... 4 more
java.lang.RuntimeException: Unrecoverable error while evaluating node 'ActionLookupData{actionLookupKey=com.google.devtools.build.lib.skyframe.CoverageReportValue$CoverageReportKey@46c9a92e, actionIndex=1}' (requested by nodes )
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:528)
        at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:399)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: null for File:[[<execution_root>]bazel-out/host/bin]external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main.jar
        at com.google.devtools.build.lib.skyframe.ActionMetadataHandler.getMetadata(ActionMetadataHandler.java:212)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$DelegatingPairFileCache.getMetadata(SkyframeActionExecutor.java:1537)
        at com.google.devtools.build.lib.remote.merkletree.InputTree.build(InputTree.java:294)
        at com.google.devtools.build.lib.remote.merkletree.InputTree.build(InputTree.java:255)
        at com.google.devtools.build.lib.remote.merkletree.MerkleTree.build(MerkleTree.java:94)
        at com.google.devtools.build.lib.remote.RemoteSpawnCache.lookup(RemoteSpawnCache.java:129)
        at com.google.devtools.build.lib.exec.AbstractSpawnStrategy.exec(AbstractSpawnStrategy.java:118)
        at com.google.devtools.build.lib.exec.AbstractSpawnStrategy.exec(AbstractSpawnStrategy.java:88)
        at com.google.devtools.build.lib.exec.ProxySpawnActionContext.exec(ProxySpawnActionContext.java:52)
        at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder$CoverageReportAction.execute(CoverageReportActionBuilder.java:126)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$4.execute(SkyframeActionExecutor.java:841)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$ActionRunner.continueAction(SkyframeActionExecutor.java:975)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$ActionRunner.run(SkyframeActionExecutor.java:947)
        at com.google.devtools.build.lib.skyframe.ActionExecutionState.runStateMachine(ActionExecutionState.java:116)
        at com.google.devtools.build.lib.skyframe.ActionExecutionState.getResultOrDependOnFuture(ActionExecutionState.java:77)
        at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.executeAction(SkyframeActionExecutor.java:571)
        at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.checkCacheAndExecuteIfNeeded(ActionExecutionFunction.java:742)
        at com.google.devtools.build.lib.skyframe.ActionExecutionFunction.compute(ActionExecutionFunction.java:260)
        at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:451)

Any idea?
Bazel version: Build label: 0.28.1-homebrew

@codesuki
Copy link

codesuki commented Aug 9, 2019

The reason was using --disk_cache. This doesn't seem to work well with CoverageOutputGenerator

@sgammon
Copy link

sgammon commented Aug 9, 2019

@codesku thank you for sharing, that might save us too :(

@georgewu2007
Copy link

So what is correct command to generate the coverage output?

@davido
Copy link
Contributor

davido commented Oct 6, 2019

Even if I disable --disk_cache (that is of course really bad), it still doesn't work for Gerrit project@HEAD, on bazel 0.29.1 and on bazel@HEAD:

   $ bazel coverage -s --test_output=all --coverage_report_generator=@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main --combined_report=lcov javatests/com/google/gerrit/server:server_tests
INFO: Writing tracer profile to '/home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/command.profile.gz'
DEBUG: /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/bazel_toolchains/rules/version_check.bzl:45:9: 
Current running Bazel is not a release version and one was not defined explicitly in rbe_autoconfig target. Falling back to '0.25.2'
DEBUG: /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/external/bazel_skylib/lib/versions.bzl:96:13: Current Bazel is not a release version; cannot check for compatibility. Make sure that you are running at least Bazel 0.29.1.
INFO: Using default value for --instrumentation_filter: "//java/com/google/gerrit/server[/:]".
INFO: Override the above default with --instrumentation_filter
INFO: Build option --coverage_report_generator has changed, discarding analysis cache.
INFO: Analyzed target //javatests/com/google/gerrit/server:server_tests (0 packages loaded, 3893 targets configured).
INFO: Found 1 test target...
SUBCOMMAND: # (unknown) [action 'CoverageReport _coverage/_coverage_report.dat', configuration: system]
(cd /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/execroot/gerrit && \
  exec env - \
    JAVA_RUNFILES=bazel-out/host/bin/external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main.runfiles \
    PYTHON_RUNFILES=bazel-out/host/bin/external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main.runfiles \
  bazel-out/host/bin/external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main '--reports_file=bazel-out/_coverage/lcov_files.tmp' '--output_file=bazel-out/_coverage/_coverage_report.dat')
ERROR: Coverage report generation failed:  failed (Exit 127)
bazel-out/host/bin/external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main: line 351: /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/execroot/gerrit/bazel-out/host/bin/external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main.runfiles/remotejdk11_linux/bin/java: No such file or directory
Target //javatests/com/google/gerrit/server:server_tests up-to-date:
  bazel-bin/javatests/com/google/gerrit/server/server_tests.jar
  bazel-bin/javatests/com/google/gerrit/server/server_tests
INFO: Elapsed time: 0.936s, Critical Path: 0.18s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

The problem seems to be, that it cannot find JDK:

ERROR: Coverage report generation failed:  failed (Exit 127)
bazel-out/host/bin/external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main: line 351: /home/davido/.cache/bazel/_bazel_davido/5c01f4f713b675540b8b424c5c647f63/execroot/gerrit/bazel-out/host/bin/external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main.runfiles/remotejdk11_linux/bin/java: No such file or directory

regisd added a commit to regisd/jflex that referenced this issue Nov 25, 2019
regisd added a commit to jflex-de/jflex that referenced this issue Nov 25, 2019
Workaround suggested by codesuki bazelbuild/bazel#6450 (comment)

Against
Internal error thrown during build. Printing stack trace: java.lang.RuntimeException: Unrecoverable error while evaluating node 'ActionLookupData{actionLookupKey=com.google.devtools.build.lib.skyframe.CoverageReportValue$CoverageReportKey@7beaf6d6, actionIndex=1}' (requested by nodes )
	at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:531)
	at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:399)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: null for File:[[<execution_root>]bazel-out/host/bin]external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main.jar
	at com.google.devtools.build.lib.skyframe.ActionMetadataHandler.getMetadata(ActionMetadataHandler.java:210)
	at com.google.devtools.build.lib.skyframe.SkyframeActionExecutor$DelegatingPairFileCache.getMetadata(SkyframeActionExecutor.java:1604)

https://cirrus-ci.com/task/5105954051325952?command=measure_and_aggregate_coverage#L279
regisd added a commit to jflex-de/jflex that referenced this issue Nov 25, 2019
* Build coverage reports with Bazel
  * Gave up with aggregated report (combined_report)
     bazelbuild/bazel#6450
     https://cirrus-ci.com/task/5105954051325952?command=measure_and_aggregate_coverage#L279

* Add code coverage as a Cirrus CI task
  * Add CODACY_PROJECT_TOKEN to Cirrus env variables

* Remove Maven report-module
regisd pushed a commit to jflex-de/jflex that referenced this issue Nov 25, 2019
Author: Régis Décamps <regisd@google.com>
Date:   Tue Nov 26 00:18:30 2019 +0100

    Send code coverage reports (#608)

    * Build coverage reports with Bazel
      * Gave up with aggregated report (combined_report)
         bazelbuild/bazel#6450
         https://cirrus-ci.com/task/5105954051325952?command=measure_and_aggregate_coverage#L279

    * Add code coverage as a Cirrus CI task
      * Add CODACY_PROJECT_TOKEN to Cirrus env variables

    * Remove Maven report-module

Updated from target/jflex-parent-1.8.0-SNAPSHOT-sources.jar
@ulfjack
Copy link
Contributor

ulfjack commented Dec 12, 2019

From manual testing, this is fixed as of 934c4fd.

@ulfjack ulfjack closed this as completed Dec 12, 2019
@c16a
Copy link

c16a commented Dec 24, 2019

I still have this issue with Bazel 2.0.0

@mukul-rathi
Copy link

I also still have this issue when running bazel coverage --combined_report=lcov //...

What operating system are you running Bazel on?

MacOS Mojave Version 10.14.6

Output of bazel info release:

release 2.0.0

I'm on a C++ repo using GoogleTest.

Output

INFO: Using default value for --instrumentation_filter: "//tests/llvm-backend[/:]".
INFO: Override the above default with --instrumentation_filter
Internal error thrown during build. Printing stack trace: java.lang.NullPointerException
        at com.google.devtools.build.lib.bazel.coverage.BazelCoverageReportModule$1.getArgs(BazelCoverageReportModule.java:115)
        at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder.generateCoverageReportAction(CoverageReportActionBuilder.java:246)
        at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder.createCoverageActionsWrapper(CoverageReportActionBuilder.java:193)
        at com.google.devtools.build.lib.bazel.coverage.BazelCoverageReportModule$1.createCoverageReportActionsWrapper(BazelCoverageReportModule.java:97)
        at com.google.devtools.build.lib.analysis.BuildView.createResult(BuildView.java:488)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:431)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:212)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:124)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:143)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:271)
        at com.google.devtools.build.lib.runtime.commands.TestCommand.doTest(TestCommand.java:130)
        at com.google.devtools.build.lib.runtime.commands.TestCommand.exec(TestCommand.java:108)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:543)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:205)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:601)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$2(GrpcServerImpl.java:652)
        at io.grpc.Context$1.run(Context.java:595)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)

INFO: Elapsed time: 0.099s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
Internal error thrown during build. Printing stack trace: java.lang.NullPointerException
        at com.google.devtools.build.lib.bazel.coverage.BazelCoverageReportModule$1.getArgs(BazelCoverageReportModule.java:115)
        at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder.generateCoverageReportAction(CoverageReportActionBuilder.java:246)
        at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder.createCoverageActionsWrapper(CoverageReportActionBuilder.java:193)
        at com.google.devtools.build.lib.bazel.coverage.BazelCoverageReportModule$1.createCoverageReportActionsWrapper(BazelCoverageReportModule.java:97)
        at com.google.devtools.build.lib.analysis.BuildView.createResult(BuildView.java:488)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:431)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:212)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:124)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:143)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:271)
        at com.google.devtools.build.lib.runtime.commands.TestCommand.doTest(TestCommand.java:130)
        at com.google.devtools.build.lib.runtime.commands.TestCommand.exec(TestCommand.java:108)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:543)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:205)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:601)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$2(GrpcServerImpl.java:652)
        at io.grpc.Context$1.run(Context.java:595)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
        at com.google.devtools.build.lib.bazel.coverage.BazelCoverageReportModule$1.getArgs(BazelCoverageReportModule.java:115)
        at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder.generateCoverageReportAction(CoverageReportActionBuilder.java:246)
        at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder.createCoverageActionsWrapper(CoverageReportActionBuilder.java:193)
        at com.google.devtools.build.lib.bazel.coverage.BazelCoverageReportModule$1.createCoverageReportActionsWrapper(BazelCoverageReportModule.java:97)
        at com.google.devtools.build.lib.analysis.BuildView.createResult(BuildView.java:488)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:431)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:212)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:124)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:143)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:271)
        at com.google.devtools.build.lib.runtime.commands.TestCommand.doTest(TestCommand.java:130)
        at com.google.devtools.build.lib.runtime.commands.TestCommand.exec(TestCommand.java:108)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:543)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:205)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:601)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$2(GrpcServerImpl.java:652)
        at io.grpc.Context$1.run(Context.java:595)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)

@c16a
Copy link

c16a commented Jan 5, 2020

@iirina seems like folks across languages are facing this issue. Any clue what the issue is?

bazel test //... fails for me.

@ulfjack
Copy link
Contributor

ulfjack commented Jan 6, 2020

The fix didn't make it into 2.0.0.

@c16a
Copy link

c16a commented Jan 7, 2020

Any ETA of when this might be merged? Looks like this is a widespread issue for people?

@ulfjack
Copy link
Contributor

ulfjack commented Jan 7, 2020

It should work at HEAD, and I expect it to be in the next release, which is probably 2.1.0.

@speakmore
Copy link

There are a lot of affected users who are running with various lower versions. And there is significant amount of work to upgrade to 2.0.0 (or 2.1.0).
For bug like this, can we also cherrypick the fix to some of release versions, such as 1.0.0?

Also, code coverage is import functionality to guarantee code quality. Is it possible to add some tests to make sure it won't break easily again?

Thanks!

@sgammon
Copy link

sgammon commented Feb 14, 2020

@ulfjack / on 2.1.0, i'm getting an error still with this flag:

Caused by: java.lang.NoClassDefFoundError: org/jacoco/agent/rt/internal_1f1cc91/Offline
	at elemental2.core.BuiltInClosureTypeCleaner.$jacocoInit(BuiltInClosureTypeCleaner.java)
	at elemental2.core.BuiltInClosureTypeCleaner.<init>(BuiltInClosureTypeCleaner.java)
	... 9 more
Caused by: java.lang.ClassNotFoundException: org.jacoco.agent.rt.internal_1f1cc91.Offline
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)

@ulfjack
Copy link
Contributor

ulfjack commented Feb 17, 2020

See my reply on #5426, which - I think - is the right bug.

@greenwind89
Copy link

greenwind89 commented Jul 22, 2020

Just for anyone who stumbles across this issue like I do, I am using an old Bazel version: 0.24.0. There is a change in Bazel 0.19.0, you need to change into --coverage_report_generator=@bazel_tools//tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator:Main to make it work.

Release note here https://blog.bazel.build/2018/10/29/bazel-0.19.0.html

@lberki
Copy link
Contributor

lberki commented Nov 16, 2022

This still happens at HEAD:

bazel coverage --combined_report=lcov --coverage_report_generator=<an sh_library rule> <a cc_test rule>

crashes with the following stack trace:

java.lang.NullPointerException
        at com.google.devtools.build.lib.bazel.coverage.BazelCoverageReportModule$1.getArgs(BazelCoverageReportModule.java:118)
        at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder.generateCoverageReportAction(CoverageReportActionBuilder.java:283)
        at com.google.devtools.build.lib.bazel.coverage.CoverageReportActionBuilder.createCoverageActionsWrapper(CoverageReportActionBuilder.java:229)
        at com.google.devtools.build.lib.bazel.coverage.BazelCoverageReportModule$1.createCoverageReportActionsWrapper(BazelCoverageReportModule.java:100)
        at com.google.devtools.build.lib.analysis.BuildView.createResult(BuildView.java:570)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:504)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:234)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:139)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:180)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:502)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:470)
        at com.google.devtools.build.lib.runtime.commands.TestCommand.doTest(TestCommand.java:148)
        at com.google.devtools.build.lib.runtime.commands.TestCommand.exec(TestCommand.java:113)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:608)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:233)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:550)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$1(GrpcServerImpl.java:614)
        at io.grpc.Context$1.run(Context.java:566)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)

I'm fairly certain that this is due to a missing FilesToRunProvider because binary rules in --coverage_report_generator do work.

cc @c-mita

@lberki lberki added team-Rules-Server Issues for serverside rules included with Bazel untriaged and removed team-Rules-Java Issues for Java rules P2 We'll consider working on this in future. (Assignee optional) labels Nov 16, 2022
@c-mita
Copy link
Member

c-mita commented Nov 16, 2022

That looks like the most likely reason for an NPE (getExecutable returns null). We can add a check here to avoid the crash, but the input tool definitely need to be executable.

@lberki
Copy link
Contributor

lberki commented Nov 16, 2022

Yeah, that's all I'm asking for; one can't do much with a tool that's not executable, it's just that crashing is not acceptable.

@comius comius added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coverage P2 We'll consider working on this in future. (Assignee optional) team-Rules-Server Issues for serverside rules included with Bazel type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.