bazel: Bazel build crash with IllegalArgumentException
This is bazel 0.22.0, on an otherwise clean machine.
$ bazel build //java/info/adams/self
Starting local Bazel server and connecting to it...
INFO: Invocation ID: d4aa1a5e-eba4-4f08-b033-f974134d23b2
INFO: Analysed target //java/info/adams/self:self (16 packages loaded, 389 targets configured).
INFO: Found 1 target...
ERROR: /home/ulfjack/.cache/bazel/_bazel_ulfjack/d8cef0f170ae4455e05403d45c33884b/external/bazel_tools/tools/jdk/BUILD:188:1: SkylarkAction external/bazel_tools/tools/jdk/platformclasspath.jar failed (Exit 1) java failed: error executing command external/remotejdk_linux/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' -cp ... (remaining 4 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
Exception in thread "main" java.lang.IllegalArgumentException: external/local_jdk
at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.update(Unknown Source)
at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.handleOption(Unknown Source)
at jdk.compiler/com.sun.tools.javac.file.Locations.handleOption(Unknown Source)
at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(Unknown Source)
at jdk.compiler/com.sun.tools.javac.file.BaseFileManager$2.handleFileManagerOption(Unknown Source)
at jdk.compiler/com.sun.tools.javac.main.Option.process(Unknown Source)
at jdk.compiler/com.sun.tools.javac.main.Option.handleOption(Unknown Source)
at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(Unknown Source)
at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Unknown Source)
at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Unknown Source)
at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Unknown Source)
at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(Unknown Source)
at DumpPlatformClassPath.dumpJDK9AndNewerBootClassPath(DumpPlatformClassPath.java:106)
at DumpPlatformClassPath.main(DumpPlatformClassPath.java:67)
Target //java/info/adams/self:self failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 36.836s, Critical Path: 3.83s
INFO: 1 process: 1 linux-sandbox.
FAILED: Build did NOT complete successfully
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 21 (18 by maintainers)
Commits related to this issue
- Install JDK for Mac CI builds (#54) Latest XCode image for CircleCI (`10.1`) does not have installed JDK, which prevents `bazel` to build code (relevant issue: https://github.com/bazelbuild/bazel/iss... — committed to vaticle/dependencies by vmax 5 years ago
- Fix `test-assembly-mac-zip` and `test-assembly-windows-zip` CI jobs (#5215) ## What is the goal of this PR? - Fix `test-assembly-mac-zip` which was broken because of upgrading `bazel` to latest v... — committed to vaticle/typedb by vmax 5 years ago
Tobi and me found the problem, a fix and a workaround. 😃
The problem: When JAVA_HOME is set to point to a JRE 8 instead of a JDK, Bazel will happily try to use it, but then chaos unfolds in DumpPlatformClassPath:
This method tries to detect whether the target (= system) JDK is a) Java 8 or b) Java >=9: https://source.bazel.build/bazel/+/28841a6c4fe303e661041e479f78ed8197a82548:tools/jdk/DumpPlatformClassPath.java;l=95
It does so by making the assumption: If we look for well-known files of OpenJDK 8 and they don’t exist, then it must be an OpenJDK >= 9. This check obviously also comes to the conclusion that you’re looking at OpenJDK >= 9 when you’re not looking at a JDK at all (like a JRE).
DumpPlatformClassPath passes the path to its logic for OpenJDK 9 boot classpath detection, which then crashes with an InvalidArgumentException, because it refuses to work with something that’s not an OpenJDK >= 9.
The fix: https://github.com/bazelbuild/bazel/pull/7324
The workaround: Set JAVA_HOME to a JDK on platforms where that’s not the case, like in the Cloud Shell container. I verified that on Cloud Shell the JAVA_HOME is set incorrectly to a JRE:
By setting it to the JDK (
/usr/lib/jvm/java-8-openjdk-amd64
) instead, Bazel works fine.In my case it turns to be missing the jdk at all, so
solved the problem