From d90ec67fdab9710f649a3c1d374fb6b938b9271a Mon Sep 17 00:00:00 2001 From: Ivo List Date: Fri, 4 Dec 2020 02:37:16 -0800 Subject: [PATCH] Fix NPE when coveragerunner is not set on the toolchain. Fixes https://github.com/bazelbuild/bazel/issues/12619 Closes #12625. PiperOrigin-RevId: 345638551 --- .../lib/rules/java/JavaCompilationHelper.java | 1 + .../shell/bazel/bazel_java_test_defaults.sh | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java index cedb6f836c9243..66ed0575908d0b 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java @@ -378,6 +378,7 @@ public void addCoverageSupport() { if (jacocoRunner == null) { ruleContext.ruleError( "jacocorunner not set in java_toolchain:" + javaToolchain.getToolchainLabel()); + return; } Artifact jacocoRunnerJar = jacocoRunner.getExecutable(); if (isStrict()) { diff --git a/src/test/shell/bazel/bazel_java_test_defaults.sh b/src/test/shell/bazel/bazel_java_test_defaults.sh index 25df9b4bd7414e..a5f18d91aa93c9 100755 --- a/src/test/shell/bazel/bazel_java_test_defaults.sh +++ b/src/test/shell/bazel/bazel_java_test_defaults.sh @@ -122,4 +122,38 @@ EOF expect_log "major version: 55" } +function test_tools_jdk_toolchain_nojacocorunner() { + mkdir -p java/main + cat >java/main/BUILD <java/main/JavaBinary.java <"${TEST_log}" \ + && fail "Coverage succeeded even when jacocorunner not set" + expect_log "jacocorunner not set in java_toolchain:" +} + run_suite "Java integration tests with default Bazel values"