Use a JDK version-specific toolchain in `bazel_java_test.sh`
e.g. for ` //src/test/shell/bazel:bazel_java_test_jdk16_toolchain_head`,
this test was previously using `@bazel_tools//tools/jdk:toolchain`, which
was leaking the toolchain from the enclosing version of Bazel. It worked
anyways because turbine was always producing JDK 8 class files, but as of
https://github.com/google/turbine/commit/006a74b6cd7565221a2d7fe9593c103bdd83584c
turbine uses the class file version corresponding to the `-target` or
`--release` flag.
This fixes e.g.
```
java/com/google/sandwich/B.java:3: error: cannot access C
C myObject;
^
bad class file: bazel-out/k8-fastbuild/bin/java/com/google/sandwich/libbottom-hjar.jar(/com/google/sandwich/C.class)
class file has wrong version 59.0, should be 55.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
```
from https://github.com/bazelbuild/bazel/pull/14059
PiperOrigin-RevId: 399738050
diff --git a/src/test/shell/bazel/bazel_java_test.sh b/src/test/shell/bazel/bazel_java_test.sh
index 35b75ad..08798da 100755
--- a/src/test/shell/bazel/bazel_java_test.sh
+++ b/src/test/shell/bazel/bazel_java_test.sh
@@ -97,6 +97,13 @@
JAVA_RUNTIME_VERSION="$1"; shift
add_to_bazelrc "build --java_runtime_version=${JAVA_RUNTIME_VERSION}"
add_to_bazelrc "build --tool_java_runtime_version=${JAVA_RUNTIME_VERSION}"
+ if [[ "${JAVA_RUNTIME_VERSION}" == 8 ]]; then
+ JAVA_TOOLCHAIN="@bazel_tools//tools/jdk:toolchain_java8"
+ elif [[ "${JAVA_RUNTIME_VERSION}" == 11 ]]; then
+ JAVA_TOOLCHAIN="@bazel_tools//tools/jdk:toolchain_java11"
+ else
+ JAVA_TOOLCHAIN="@bazel_tools//tools/jdk:toolchain_jdk_${JAVA_RUNTIME_VERSION}"
+ fi
fi
export TESTENV_DONT_BAZEL_CLEAN=1