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

Test coverage doesn't work on Java 16 toolchain #13358

Closed
davido opened this issue Apr 15, 2021 · 12 comments
Closed

Test coverage doesn't work on Java 16 toolchain #13358

davido opened this issue Apr 15, 2021 · 12 comments
Labels
coverage P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules

Comments

@davido
Copy link
Contributor

davido commented Apr 15, 2021

Trying to run test coverage with new and shiny Java 16 toolchain support is failing.

Reproducer: https://github.com/davido/bazel_coverage. Note, that .bazelrc already switching to Java 16 toolchain, you make sure, that your bazel version includes this PR.

  $ bazel coverage :test
[...]
java.util.zip.ZipException: zip END header not found

.Exception in thread "main" java.lang.IllegalStateException: JACOCO_METADATA_JAR/JACOCO_MAIN_CLASS environment 
variables not set, and no META-INF/MANIFEST.MF on the classpath has a Coverage-Main-Class attribute.  Cannot 
determine the name of the main class for the code under test.
	at com.google.testing.coverage.JacocoCoverageRunner.getMainClass(JacocoCoverageRunner.java:323)

.Exception in thread "main" java.lang.ClassNotFoundException: com.google.testing.junit.runner.BazelTestRunner

The problem could be related to some new visibility/exports requirement in JDK16?

The full log is here:

$ cat /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/testlogs/test/test.log
exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //:test
-----------------------------------------------------------------------------
+ [[ -z bazel-out/k8-fastbuild/bin/test.instrumented_files ]]
+ export ROOT=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__
+ ROOT=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__
+ [[ bazel-out/k8-fastbuild/bin/test.instrumented_files != /* ]]
+ export COVERAGE_MANIFEST=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.instrumented_files
+ COVERAGE_MANIFEST=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.instrumented_files
+ export COVERAGE_DIR=_coverage/test/test
+ COVERAGE_DIR=_coverage/test/test
+ [[ _coverage/test/test == /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__* ]]
+ COVERAGE_DIR=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test
+ mkdir -p /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test
+ COVERAGE_OUTPUT_FILE=bazel-out/k8-fastbuild/testlogs/test/coverage.dat
+ [[ bazel-out/k8-fastbuild/testlogs/test/coverage.dat == /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__* ]]
+ COVERAGE_OUTPUT_FILE=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/testlogs/test/coverage.dat
+ export JAVA_COVERAGE_FILE=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test/jvcov.dat
+ JAVA_COVERAGE_FILE=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test/jvcov.dat
+ export COVERAGE=1
+ COVERAGE=1
+ export BULK_COVERAGE_RUN=1
+ BULK_COVERAGE_RUN=1
+ for name in "$LCOV_MERGER"
+ [[ ! -e bazel-out/k8-opt-exec-2B5CBBC6/bin/external/remote_coverage_tools/Main ]]
+ [[ -z '' ]]
+ export GCOV_PREFIX_STRIP=3
+ GCOV_PREFIX_STRIP=3
+ export GCOV_PREFIX=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test
+ GCOV_PREFIX=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test
+ export LLVM_PROFILE_FILE=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test/%h-%p-%m.profraw
+ LLVM_PROFILE_FILE=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test/%h-%p-%m.profraw
+ [[ ! -z bazel-out/k8-fastbuild/bin/runtime_classpath_for_coverage/test/runtime_classpath.txt ]]
+ JAVA_RUNTIME_CLASSPATH_FOR_COVERAGE=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/runtime_classpath_for_coverage/test/runtime_classpath.txt
+ SINGLE_JAR_TOOL=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/external/remote_java_tools_linux/java_tools/src/tools/singlejar/singlejar_local
+ mkdir -p /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test
+ single_jar_params_file=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test/runtime_classpath.paramsfile
+ touch /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test/runtime_classpath.paramsfile
+ export JACOCO_METADATA_JAR=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test/coverage-runtime_merged_instr.jar
+ JACOCO_METADATA_JAR=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test/coverage-runtime_merged_instr.jar
+ echo -e '--output /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test/coverage-runtime_merged_instr.jar\n--sources'
+ RUNFILES_PREFIX=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/
+ cat /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/runtime_classpath_for_coverage/test/runtime_classpath.txt
+ sed 's@^@/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/@'
+ /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/external/remote_java_tools_linux/java_tools/src/tools/singlejar/singlejar_local @/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_coverage/test/test/runtime_classpath.paramsfile
singlejar_local: ./src/tools/singlejar/mapped_file_posix.inc:42: open /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/java_tools/JacocoCoverage_jarjar_deploy.jar:: No such file or directory
singlejar_local: src/tools/singlejar/input_jar.cc:24: Cannot open input jar /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/java_tools/JacocoCoverage_jarjar_deploy.jar: No such file or directory
+ [[ 0 == \0 ]]
+ cd /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__
+ [[ 0 == \0 ]]
+ touch /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/testlogs/test/coverage.dat
+ /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/test
JUnit4 Test Runner
.
Time: 0.021

OK (1 test)


BazelTestRunner exiting with a return value of 0
JVM shutdown hooks (if any) will run now.
The JVM will exit once they complete.

-- JVM shutdown starting at 2021-04-15 07:20:08 --

java.util.zip.ZipException: zip END header not found
	at java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1587)
	at java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1441)
	at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1450)
	at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1263)
	at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1225)
	at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:706)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:240)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:171)
	at java.base/java.util.jar.JarFile.<init>(JarFile.java:349)
	at java.base/java.util.jar.JarFile.<init>(JarFile.java:320)
	at java.base/java.util.jar.JarFile.<init>(JarFile.java:286)
	at com.google.testing.coverage.JacocoCoverageRunner.analyzeUninstrumentedClassesFromJar(JacocoCoverageRunner.java:223)
	at com.google.testing.coverage.JacocoCoverageRunner.analyzeStructure(JacocoCoverageRunner.java:183)
	at com.google.testing.coverage.JacocoCoverageRunner.create(JacocoCoverageRunner.java:129)
	at com.google.testing.coverage.JacocoCoverageRunner$2.run(JacocoCoverageRunner.java:551)
+ TEST_STATUS=1
+ [[ 1 -ne 0 ]]
+ echo --
--
+ echo Coverage runner: Not collecting coverage for failed test.
Coverage runner: Not collecting coverage for failed test.
+ echo The following commands failed with status 1
The following commands failed with status 1
+ echo /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/test
/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/test
+ exit 1

//CC @cushon @comius

@comius comius added team-Rules-Java Issues for Java rules P3 We're not considering working on this, but happy to review a PR. (No assignee) coverage labels Apr 15, 2021
davido added a commit to davido/bazel that referenced this issue Apr 15, 2021
@davido
Copy link
Contributor Author

davido commented Apr 15, 2021

I activated the coverage tests for Java 16 toolchain again to demonstrate the failure: #13361.

@comius
Copy link
Contributor

comius commented Apr 15, 2021

/cc @c-mita

@cushon
Copy link
Contributor

cushon commented Apr 16, 2021

The zip it's crashing on is execroot/__main__/_coverage/test/test/coverage-runtime_merged_instr.jar.

That jar is created by the singlejar invocation in the log, which is printing errors:

singlejar_local: ./src/tools/singlejar/mapped_file_posix.inc:42: open ./execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/java_tools/JacocoCoverage_jarjar_deploy.jar:: No such file or directory
singlejar_local: src/tools/singlejar/input_jar.cc:24: Cannot open input jar ./execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/java_tools/JacocoCoverage_jarjar_deploy.jar: No such file or directory

The correct path appears to be e.g.:

-execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/java_tools/JacocoCoverage_jarjar_deploy.jar
+execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/remote_java_tools/java_tools/JacocoCoverage_jarjar_deploy.jar

The paths in the singlejar command line are being constructed here:

# Append the runfiles prefix to all the relative paths found in
# JAVA_RUNTIME_CLASSPATH_FOR_COVERAGE, to invoke SingleJar with the
# absolute paths.
RUNFILES_PREFIX="$TEST_SRCDIR/$TEST_WORKSPACE/"
cat "$JAVA_RUNTIME_CLASSPATH_FOR_COVERAGE" | sed "s@^@$RUNFILES_PREFIX@" >> "$single_jar_params_file"

I'm still confused about what actually changed in JDK 16, as far as I can tell under earlier JDK versions the singlejar command line was also malformed and coverage-runtime_merged_instr.jar was not being created correctly.

I almost wonder if something in JDK 16 changed the behaviour of the shutdown hook in JacocoCoverageRunner that's trying to read that malformed jar, i.e. maybe it was malformed before but the error wasn't getting reported?

@davido
Copy link
Contributor Author

davido commented Apr 19, 2021

Thanks for analysis.

I also saw the same issues with Java 15 toolchain. classpath file is misconfigured and resulted merged jar cannot be read, but there is no error in Java 15 toolchain.

I have problem to reproduce the failure on command line. With this diff:

diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt
index 4394666ab6..8ad81c9fef 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/java_stub_template.txt
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/bash -x
 # Copyright 2014 The Bazel Authors. All rights reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");

I can see the command that is executed:

  $ bazeldev coverage -s :test
  [...]
  + export CLASSLOADER_PREFIX_PATH=
+ CLASSLOADER_PREFIX_PATH=
+ export JACOCO_MAIN_CLASS=com.google.testing.junit.runner.BazelTestRunner
+ JACOCO_MAIN_CLASS=com.google.testing.junit.runner.BazelTestRunner
+ export JACOCO_JAVA_RUNFILES_ROOT=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/
+ JACOCO_JAVA_RUNFILES_ROOT=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/
+ export JACOCO_IS_JAR_WRAPPED=0
+ JACOCO_IS_JAR_WRAPPED=0
+ [[ -n '' ]]
+ [[ -n '' ]]
+ [[ -n /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_tmp/ca81b3a3ed4bd62e8ca9ec8ba8fc904c ]]
+ [[ -d /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_tmp/ca81b3a3ed4bd62e8ca9ec8ba8fc904c ]]
+ JVM_FLAGS+=' -Djava.io.tmpdir=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_tmp/ca81b3a3ed4bd62e8ca9ec8ba8fc904c'
+ ARGS=(${JVM_DEBUG_FLAGS} ${JVM_FLAGS} -ea -Dbazel.test_suite=com.example.TestCollatz "${JVM_FLAGS_CMDLINE[@]}" ${MAIN_ADVICE} com.google.testing.coverage.JacocoCoverageRunner "${ARGS[@]}")
+ '[' -z '' ']'
+ is_windows
+ [[ linux-gnu =~ msys* ]]
+ [[ linux-gnu =~ cygwin* ]]
+ CLASSPATH_LIMIT=120000
+ (( 142 > 120000 ))
+ exec /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/remotejdk16_linux/bin/java -classpath test.jar:../remote_java_tools/java_tools/JacocoCoverage_jarjar_deploy.jar:libcollatz-lib.jar:../remote_java_tools/java_tools/Runner_deploy.jar -Djava.io.tmpdir=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_tmp/ca81b3a3ed4bd62e8ca9ec8ba8fc904c -ea -Dbazel.test_suite=com.example.TestCollatz com.google.testing.coverage.JacocoCoverageRunner
JUnit4 Test Runner
.
Time: 0.02

OK (1 test)


BazelTestRunner exiting with a return value of 0
JVM shutdown hooks (if any) will run now.
The JVM will exit once they complete.

-- JVM shutdown starting at 2021-04-19 06:51:14 --

java.util.zip.ZipException: zip END header not found
	at java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1587)
	at java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1441)
	at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1450)
	at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1263)
	at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1225)
	at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:706)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:240)
	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:171)
	at java.base/java.util.jar.JarFile.<init>(JarFile.java:349)
	at java.base/java.util.jar.JarFile.<init>(JarFile.java:320)
	at java.base/java.util.jar.JarFile.<init>(JarFile.java:286)
	at com.google.testing.coverage.JacocoCoverageRunner.analyzeUninstrumentedClassesFromJar(JacocoCoverageRunner.java:223)
	at com.google.testing.coverage.JacocoCoverageRunner.analyzeStructure(JacocoCoverageRunner.java:183)
	at com.google.testing.coverage.JacocoCoverageRunner.create(JacocoCoverageRunner.java:129)
	at com.google.testing.coverage.JacocoCoverageRunner$2.run(JacocoCoverageRunner.java:551)
+ TEST_STATUS=1
+ [[ 1 -ne 0 ]]
+ echo --
--
+ echo Coverage runner: Not collecting coverage for failed test.
Coverage runner: Not collecting coverage for failed test.
+ echo The following commands failed with status 1
The following commands failed with status 1
+ echo /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/test
/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/__main__/test
+ exit 1
================================================================================
Target //:test up-to-date:
  bazel-bin/test.jar
  bazel-bin/test
INFO: Elapsed time: 0.464s, Critical Path: 0.34s
INFO: 2 processes: 1 internal, 1 local.
INFO: Build completed, 1 test FAILED, 2 total actions
//:test                                                                  FAILED in 0.3s
  /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/testlogs/test/test.log

INFO: Build completed, 1 test FAILED, 2 total actions

However, if I re-run the command:

  $ /home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/bazel-out/k8-fastbuild/bin/test.runfiles/remotejdk16_linux/bin/java -classpath test.jar:../remote_java_tools/java_tools/JacocoCoverage_jarjar_deploy.jar:libcollatz-lib.jar:../remote_java_tools/java_tools/Runner_deploy.jar -Djava.io.tmpdir=/home/davido/.cache/bazel/_bazel_davido/d2e4628c65018481d7632ab5397b30b3/execroot/__main__/_tmp/ca81b3a3ed4bd62e8ca9ec8ba8fc904c -ea -Dbazel.test_suite=com.example.TestCollatz com.google.testing.coverage.JacocoCoverageRunner

there is no failure.

@cushon
Copy link
Contributor

cushon commented Apr 21, 2021

This is fixed by 8ba48ad

@cushon cushon closed this as completed Apr 21, 2021
davido added a commit to davido/bazel that referenced this issue Apr 22, 2021
@davido
Copy link
Contributor Author

davido commented Apr 22, 2021

Thanks, I can confirm that coverage works now on Bazel@HEAD. Still the #13361 is needed to enable the disabled coverage tests for Java 16 toolchain.

@davido
Copy link
Contributor Author

davido commented Apr 22, 2021

@cushon @comius @ulfjack

Can you please reopen this issue? Turns out another coverage test is still failing on Java 16 toolchain, even with 8ba48ad included (as can be seen in the PR linked to this issue).

I extracted this reproducer: https://github.com/davido/bazel_cov.

@comius comius reopened this Apr 22, 2021
@cushon
Copy link
Contributor

cushon commented Apr 22, 2021

This looks like it has a similar root cause to the other issue: the coverage runtime classpath contains an entry that doesn't exist, which is now failing the test. I think the paths were wrong all along, it was just being silently ignored before.

singlejar_local: ./src/tools/singlejar/mapped_file_posix.inc:42: open /usr/local/google/home/cushon/.cache/bazel/_bazel_cushon/4993a912683d2c58bfca539c40e4f995/execroot/__main__/bazel-out/k8-fastbuild/bin/javatests/cov/CovTest.runfiles/__main__/java/cov/Cov.jar:: No such file or directory

The test depends on that deploy jar via data:

java_test(name = 'CovTest',
          srcs = ['CovTest.java'],
          data = ['//java/cov:Cov_deploy.jar'],
          test_class = 'cov.CovTest')

Note Cov.jar vs. Cov_deploy.jar. I suspect there's some weirdness about how coverage applies to data.

I'm a little confused about Cov.jar is even considered as being on the runtime classpath here

.addTransitiveArtifactsWrappedInStableOrder(common.getRuntimeClasspath())
, since it's in data.

@davido
Copy link
Contributor Author

davido commented Apr 23, 2021

Yes, even if I run coverage with vanilla Java 11 toolchain, also with this diff in reproducer:

diff --git a/.bazelrc b/.bazelrc
index c5e3cb0..5f419bd 100644
--- a/.bazelrc
+++ b/.bazelrc
@@ -1,6 +1,6 @@
 # Builds using remote_jdk16, executes using remote_jdk16 or local_jdk
-build --java_language_version=16
-build --java_runtime_version=16
-build --tool_java_language_version=16
-build --tool_java_runtime_version=16
+#build --java_language_version=16
+#build --java_runtime_version=16
+#build --tool_java_language_version=16
+#build --tool_java_runtime_version=16

I'm still getting exactly the same misconfigured classpath:

  $ bazel coverage -s javatests/cov:CovTest
  [...]
  INFO: Elapsed time: 44.423s, Critical Path: 6.23s
INFO: 26 processes: 16 internal, 7 linux-sandbox, 3 worker.
INFO: Build completed successfully, 26 total actions
//javatests/cov:CovTest                                                  PASSED in 0.7s

   $ cat bazel-out/k8-fastbuild/testlogs/javatests/cov/CovTest/test.log
  [...]
  singlejar_local: ./src/tools/singlejar/mapped_file_posix.inc:42: open /home/davido/.cache/bazel/_bazel_davido/842e4e28830cd5724c3a44ec2d887148/sandbox/linux-sandbox/10/execroot/__main__/bazel-out/k8-fastbuild/bin/javatests/cov/CovTest.runfiles/__main__/java/cov/Cov.jar:: No such file or directory
singlejar_local: src/tools/singlejar/input_jar.cc:24: Cannot open input jar /home/davido/.cache/bazel/_bazel_davido/842e4e28830cd5724c3a44ec2d887148/sandbox/linux-sandbox/10/execroot/__main__/bazel-out/k8-fastbuild/bin/javatests/cov/CovTest.runfiles/__main__/java/cov/Cov.jar: No such file or directory

I also observe the same behavior for Java 15 toolchain. For some reasons it's only failing for Java 16 toolchain, while the root cause exists for all supported toolchains.

@mark-b2c2
Copy link

I too am seeing bazel coverage //...: fail using bazel 5.0.0 (and 5.1.1) when trying to use java 17 so I assume it is the same underlying problem.

java.util.zip.ZipException: zip END header not found
        at java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1469)
        at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1477)
        at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1315)
        at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1277)
        at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:709)
        at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:243)
        at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:172)
        at java.base/java.util.jar.JarFile.<init>(JarFile.java:347)
        at java.base/java.util.jar.JarFile.<init>(JarFile.java:318)
        at java.base/java.util.jar.JarFile.<init>(JarFile.java:284)
        at com.google.testing.coverage.JacocoCoverageRunner.analyzeUninstrumentedClassesFromJar(JacocoCoverageRunner.java:223)

@c-mita
Copy link
Member

c-mita commented May 13, 2022

This appears to be fixed at HEAD (after #15209). I don't know what changed in java_tools to fix it though.

davido added a commit to davido/bazel that referenced this issue May 13, 2022
davido added a commit to davido/bazel that referenced this issue May 13, 2022
The problem was fixed in latest java_tools release. Remove duplicated
variable, as it's the same now.

Closes bazelbuild#13358.
@davido
Copy link
Contributor Author

davido commented May 13, 2022

This appears to be fixed at HEAD (after #15209).

Thanks, I confirmed, that the tests are passing now, and I've updated my linked PR and removed duplicated variable definition.

@davido davido closed this as completed May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
coverage P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants