Skip to content

Commit

Permalink
Fix NPE when coveragerunner is not set on the toolchain.
Browse files Browse the repository at this point in the history
Fixes #12619

Closes #12625.

PiperOrigin-RevId: 345638551
  • Loading branch information
comius authored and philwo committed Dec 9, 2020
1 parent b4ee5f2 commit bd3fc11
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
34 changes: 34 additions & 0 deletions src/test/shell/bazel/bazel_java_test_defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,38 @@ EOF
expect_log "major version: 55"
}

function test_tools_jdk_toolchain_nojacocorunner() {
mkdir -p java/main
cat >java/main/BUILD <<EOF
java_binary(
name = 'JavaBinary',
srcs = ['JavaBinary.java'],
main_class = 'JavaBinary',
)
load(
"@bazel_tools//tools/jdk:default_java_toolchain.bzl",
"default_java_toolchain",
)
default_java_toolchain(
name = "default_toolchain",
jacocorunner = None,
visibility = ["//visibility:public"],
)
EOF

cat >java/main/JavaBinary.java <<EOF
public class JavaBinary {
public static void main(String[] args) {
System.out.println("Successfully executed JavaBinary!");
}
}
EOF
bazel coverage java/main:JavaBinary \
--java_toolchain=//java/main:default_toolchain \
--javabase=@bazel_tools//tools/jdk:remote_jdk11 \
--verbose_failures -s &>"${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"

0 comments on commit bd3fc11

Please sign in to comment.