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

Fix NPE when coveragerunner is not set on the toolchain. #12625

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"