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

Unable to build Java example using homebrew #15452

Closed
GZGavinZhao opened this issue May 10, 2022 · 7 comments
Closed

Unable to build Java example using homebrew #15452

GZGavinZhao opened this issue May 10, 2022 · 7 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: bug

Comments

@GZGavinZhao
Copy link

GZGavinZhao commented May 10, 2022

Description of the bug:

I get errors when trying to build the example project without modification at https://bazel.build/tutorials/java. I've investigated it for an hour but am still completely baffled on why I keep getting errors.

The error is the same when using the x64 version of Bazel running under Rosetta 2.

INFO: Analyzed target //:ProjectRunner (1 packages loaded, 3 targets configured).
INFO: Found 1 target...
ERROR: /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/external/bazel_tools/tools/jdk/BUILD:333:14: JavaToolchainCompileBootClasspath external/bazel_tools/tools/jdk/platformclasspath.jar failed: (Exit 1): sandbox-exec failed: error executing command 
  (cd /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/sandbox/darwin-sandbox/2/execroot/__main__ && \
  exec env - \
    TMPDIR=/var/folders/sq/0wb00kbn4f79xkvz4j1n5zvc0000gq/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/sandbox/darwin-sandbox/2/sandbox.sb /var/tmp/_bazel_zhaoji/install/e301fb5eb5984c19c92f75b75e58c08b/process-wrapper '--timeout=0' '--kill_delay=15' external/remotejdk11_macos_aarch64/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' -cp bazel-out/darwin_arm64-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes:external/remotejdk11_macos_aarch64/lib/tools.jar DumpPlatformClassPath bazel-out/darwin_arm64-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath.jar external/local_jdk)
Exception in thread "main" java.lang.IllegalArgumentException: external/local_jdk
	at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.update(Locations.java:1853)
	at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.handleOption(Locations.java:1798)
	at jdk.compiler/com.sun.tools.javac.file.Locations.handleOption(Locations.java:2062)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:269)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager$2.handleFileManagerOption(BaseFileManager.java:222)
	at jdk.compiler/com.sun.tools.javac.main.Option.process(Option.java:1138)
	at jdk.compiler/com.sun.tools.javac.main.Option.handleOption(Option.java:1086)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:232)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Arguments.java:390)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Arguments.java:347)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Arguments.java:246)
	at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:185)
	at DumpPlatformClassPath.dumpJDK9AndNewerBootClassPath(DumpPlatformClassPath.java:106)
	at DumpPlatformClassPath.main(DumpPlatformClassPath.java:67)
Target //:ProjectRunner failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.249s, Critical Path: 0.12s
INFO: 5 processes: 5 internal.
FAILED: Build did NOT complete successfully

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Use the java-tutorial example at https://github.com/bazelbuild/examples.
Run bazel build //:ProjectRunner.

Which operating system are you running Bazel on?

macOS Monterey 12.3.1 Apple M1

What is the output of bazel info release?

release 5.1.1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

n/a

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

# For Bazel
n/a

# For the Bazel example repo
https://github.com/bazelbuild/examples
b3df8fc2601ac78e8208c63b9f5d74c599857b2f
b3df8fc2601ac78e8208c63b9f5d74c599857b2f

Have you found anything relevant by searching the web?

No.

Any other information, logs, or outputs that you want to share?

JDK version: my original one was openjdk provided by Homebrew which is 18.0.1. I switched to openjdk@11 and set the corresponding JAVA_HOME variable but still got the same error. But since Bazel builds the project using its own JDK, this should not be a factor, right?

bazel info:

bazel-bin: /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin
bazel-genfiles: /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/execroot/__main__/bazel-out/darwin_arm64-fastbuild/bin
bazel-testlogs: /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/execroot/__main__/bazel-out/darwin_arm64-fastbuild/testlogs
character-encoding: file.encoding = ISO-8859-1, defaultCharset = ISO-8859-1
command_log: /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/command.log
committed-heap-size: 104MB
execution_root: /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/execroot/__main__
gc-count: 10
gc-time: 90ms
install_base: /var/tmp/_bazel_zhaoji/install/e301fb5eb5984c19c92f75b75e58c08b
java-home: /private/var/tmp/_bazel_zhaoji/install/e301fb5eb5984c19c92f75b75e58c08b/embedded_tools/jdk
java-runtime: OpenJDK Runtime Environment (build 11.0.10+9-LTS) by Azul Systems, Inc.
java-vm: OpenJDK 64-Bit Server VM (build 11.0.10+9-LTS, mixed mode) by Azul Systems, Inc.
max-heap-size: 2147MB
output_base: /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69
output_path: /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/execroot/__main__/bazel-out
package_path: %workspace%
release: release 5.1.1
repository_cache: /var/tmp/_bazel_zhaoji/cache/repos/v1
server_log: /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/java.log.fvffm37sq6l3.zhaoji.log.java.20220509-204723.27732
server_pid: 27732
used-heap-size: 59MB
workspace: /Users/**/examples/java-tutorial
@comius
Copy link
Contributor

comius commented May 18, 2022

But since Bazel builds the project using its own JDK, this should not be a factor, right?

Bazel uses its own (remote) JDK to compile and its own (sever) JDK to run, but it inspects local JDK and uses its boot classpaths, so that the produced code/jars can execute locally. And this is where the error is happening.

Here is where JDK discovery is implemented for mac:
https://cs.opensource.google/bazel/bazel/+/master:src/main/cpp/blaze_util_darwin.cc;l=169-180;drc=688a2376d997dfa795c02eb475ae8a4204d1ba37

Can you double check JAVA_HOME is set correcty?

@GZGavinZhao
Copy link
Author

@comius I can confirm my JAVA_HOME is correct:

zhaoji@FVFFM37SQ6L3 java-tutorial % git status
On branch main
Your branch is up to date with 'origin/main'.

nothing to commit, working tree clean
zhaoji@FVFFM37SQ6L3 java-tutorial % echo $JAVA_HOME
/opt/homebrew/opt/openjdk@11
zhaoji@FVFFM37SQ6L3 java-tutorial % ls $(echo $JAVA_HOME)
INSTALL_RECEIPT.json	LICENSE			README			bin			include			libexec			share
zhaoji@FVFFM37SQ6L3 java-tutorial % which java 
/opt/homebrew/opt/openjdk@11/bin/java
zhaoji@FVFFM37SQ6L3 java-tutorial % java --version
openjdk 11.0.15 2022-04-19
OpenJDK Runtime Environment Homebrew (build 11.0.15+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.15+0, mixed mode)
zhaoji@FVFFM37SQ6L3 java-tutorial % bazel build //:ProjectRunner
Starting local Bazel server and connecting to it...
INFO: Analyzed target //:ProjectRunner (47 packages loaded, 953 targets configured).
INFO: Found 1 target...
INFO: Deleting stale sandbox base /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/sandbox
ERROR: /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/external/bazel_tools/tools/jdk/BUILD:333:14: JavaToolchainCompileBootClasspath external/bazel_tools/tools/jdk/platformclasspath.jar failed: (Exit 1): java failed: error executing command external/remotejdk11_macos_aarch64/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' ... (remaining 7 arguments 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(Locations.java:1853)
	at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.handleOption(Locations.java:1798)
	at jdk.compiler/com.sun.tools.javac.file.Locations.handleOption(Locations.java:2062)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:269)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager$2.handleFileManagerOption(BaseFileManager.java:222)
	at jdk.compiler/com.sun.tools.javac.main.Option.process(Option.java:1138)
	at jdk.compiler/com.sun.tools.javac.main.Option.handleOption(Option.java:1086)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:232)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Arguments.java:390)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Arguments.java:347)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Arguments.java:246)
	at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:185)
	at DumpPlatformClassPath.dumpJDK9AndNewerBootClassPath(DumpPlatformClassPath.java:106)
	at DumpPlatformClassPath.main(DumpPlatformClassPath.java:67)
Target //:ProjectRunner failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 14.094s, Critical Path: 0.39s
INFO: 3 processes: 3 internal.
FAILED: Build did NOT complete successfully

@comius
Copy link
Contributor

comius commented May 20, 2022

The error was happening before when Java was installed with homebrew and not found. See #6993

I wonder if @ in the path is a problem.

Can you give me more debugging information? I'm interested in platformclasspath invocation, which is failing. Running your build with -s, or --verbose_failures or more directly bazel build @bazel_tools//tools/jdk:platformclasspath -s will dump it.

@GZGavinZhao
Copy link
Author

GZGavinZhao commented May 20, 2022

@comius Here are the outputs:

Command: bazel build @bazel_tools//tools/jdk:platformclasspath -s --sandbox_debug --verbose_failures

zhaoji@FVFFM37SQ6L3 java-tutorial % bazel build @bazel_tools//tools/jdk:platformclasspath -s --sandbox_debug --verbose_failures
Starting local Bazel server and connecting to it...
INFO: Analyzed target @bazel_tools//tools/jdk:platformclasspath (32 packages loaded, 513 targets configured).
INFO: Found 1 target...
SUBCOMMAND: # @bazel_tools//tools/jdk:platformclasspath [action 'JavaToolchainCompileClasses external/bazel_tools/tools/jdk/platformclasspath_classes/DumpPlatformClassPath.class', configuration: bff2ef1b0c2d90d0090e38f4b9f6af6827fa64f9a1afb111defa525de8d438b8, execution platform: @local_config_platform//:host]
(cd /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/execroot/__main__ && \
  exec env - \
  external/remotejdk11_macos_aarch64/bin/javac -source 8 -target 8 -Xlint:-options -cp external/remotejdk11_macos_aarch64/lib/tools.jar -d bazel-out/darwin_arm64-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes external/bazel_tools/tools/jdk/DumpPlatformClassPath.java)
# Configuration: bff2ef1b0c2d90d0090e38f4b9f6af6827fa64f9a1afb111defa525de8d438b8
# Execution platform: @local_config_platform//:host
SUBCOMMAND: # @bazel_tools//tools/jdk:platformclasspath [action 'JavaToolchainCompileBootClasspath external/bazel_tools/tools/jdk/platformclasspath.jar', configuration: bff2ef1b0c2d90d0090e38f4b9f6af6827fa64f9a1afb111defa525de8d438b8, execution platform: @local_config_platform//:host]
(cd /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/execroot/__main__ && \
  exec env - \
  external/remotejdk11_macos_aarch64/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' -cp bazel-out/darwin_arm64-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes:external/remotejdk11_macos_aarch64/lib/tools.jar DumpPlatformClassPath bazel-out/darwin_arm64-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath.jar external/local_jdk)
# Configuration: bff2ef1b0c2d90d0090e38f4b9f6af6827fa64f9a1afb111defa525de8d438b8
# Execution platform: @local_config_platform//:host
ERROR: /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/external/bazel_tools/tools/jdk/BUILD:333:14: JavaToolchainCompileBootClasspath external/bazel_tools/tools/jdk/platformclasspath.jar failed: (Exit 1): sandbox-exec failed: error executing command 
  (cd /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/sandbox/darwin-sandbox/2/execroot/__main__ && \
  exec env - \
    TMPDIR=/var/folders/sq/0wb00kbn4f79xkvz4j1n5zvc0000gq/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/sandbox/darwin-sandbox/2/sandbox.sb /var/tmp/_bazel_zhaoji/install/e301fb5eb5984c19c92f75b75e58c08b/process-wrapper '--timeout=0' '--kill_delay=15' external/remotejdk11_macos_aarch64/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' -cp bazel-out/darwin_arm64-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes:external/remotejdk11_macos_aarch64/lib/tools.jar DumpPlatformClassPath bazel-out/darwin_arm64-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath.jar external/local_jdk)
Exception in thread "main" java.lang.IllegalArgumentException: external/local_jdk
	at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.update(Locations.java:1853)
	at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.handleOption(Locations.java:1798)
	at jdk.compiler/com.sun.tools.javac.file.Locations.handleOption(Locations.java:2062)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:269)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager$2.handleFileManagerOption(BaseFileManager.java:222)
	at jdk.compiler/com.sun.tools.javac.main.Option.process(Option.java:1138)
	at jdk.compiler/com.sun.tools.javac.main.Option.handleOption(Option.java:1086)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:232)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Arguments.java:390)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Arguments.java:347)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Arguments.java:246)
	at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:185)
	at DumpPlatformClassPath.dumpJDK9AndNewerBootClassPath(DumpPlatformClassPath.java:106)
	at DumpPlatformClassPath.main(DumpPlatformClassPath.java:67)
Target @bazel_tools//tools/jdk:platformclasspath failed to build
INFO: Elapsed time: 9.110s, Critical Path: 1.55s
INFO: 3 processes: 2 internal, 1 darwin-sandbox.
FAILED: Build did NOT complete successfully

Command: bazel build //:ProjectRunner -s --sandbox_debug --verbose_failures

zhaoji@FVFFM37SQ6L3 java-tutorial % bazel build //:ProjectRunner -s --sandbox_debug --verbose_failures      
Starting local Bazel server and connecting to it...
INFO: Analyzed target //:ProjectRunner (47 packages loaded, 953 targets configured).
INFO: Found 1 target...
SUBCOMMAND: # @bazel_tools//tools/jdk:platformclasspath [action 'JavaToolchainCompileClasses external/bazel_tools/tools/jdk/platformclasspath_classes/DumpPlatformClassPath.class', configuration: bff2ef1b0c2d90d0090e38f4b9f6af6827fa64f9a1afb111defa525de8d438b8, execution platform: @local_config_platform//:host]
(cd /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/execroot/__main__ && \
  exec env - \
  external/remotejdk11_macos_aarch64/bin/javac -source 8 -target 8 -Xlint:-options -cp external/remotejdk11_macos_aarch64/lib/tools.jar -d bazel-out/darwin_arm64-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes external/bazel_tools/tools/jdk/DumpPlatformClassPath.java)
# Configuration: bff2ef1b0c2d90d0090e38f4b9f6af6827fa64f9a1afb111defa525de8d438b8
# Execution platform: @local_config_platform//:host
SUBCOMMAND: # @bazel_tools//tools/jdk:platformclasspath [action 'JavaToolchainCompileBootClasspath external/bazel_tools/tools/jdk/platformclasspath.jar', configuration: bff2ef1b0c2d90d0090e38f4b9f6af6827fa64f9a1afb111defa525de8d438b8, execution platform: @local_config_platform//:host]
(cd /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/execroot/__main__ && \
  exec env - \
  external/remotejdk11_macos_aarch64/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' -cp bazel-out/darwin_arm64-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes:external/remotejdk11_macos_aarch64/lib/tools.jar DumpPlatformClassPath bazel-out/darwin_arm64-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath.jar external/local_jdk)
# Configuration: bff2ef1b0c2d90d0090e38f4b9f6af6827fa64f9a1afb111defa525de8d438b8
# Execution platform: @local_config_platform//:host
ERROR: /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/external/bazel_tools/tools/jdk/BUILD:333:14: JavaToolchainCompileBootClasspath external/bazel_tools/tools/jdk/platformclasspath.jar failed: (Exit 1): sandbox-exec failed: error executing command 
  (cd /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/sandbox/darwin-sandbox/2/execroot/__main__ && \
  exec env - \
    TMPDIR=/var/folders/sq/0wb00kbn4f79xkvz4j1n5zvc0000gq/T/ \
  /usr/bin/sandbox-exec -f /private/var/tmp/_bazel_zhaoji/501bc00a98d93560d41486f9b3f21f69/sandbox/darwin-sandbox/2/sandbox.sb /var/tmp/_bazel_zhaoji/install/e301fb5eb5984c19c92f75b75e58c08b/process-wrapper '--timeout=0' '--kill_delay=15' external/remotejdk11_macos_aarch64/bin/java -XX:+IgnoreUnrecognizedVMOptions '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' -cp bazel-out/darwin_arm64-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath_classes:external/remotejdk11_macos_aarch64/lib/tools.jar DumpPlatformClassPath bazel-out/darwin_arm64-fastbuild/bin/external/bazel_tools/tools/jdk/platformclasspath.jar external/local_jdk)
Exception in thread "main" java.lang.IllegalArgumentException: external/local_jdk
	at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.update(Locations.java:1853)
	at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.handleOption(Locations.java:1798)
	at jdk.compiler/com.sun.tools.javac.file.Locations.handleOption(Locations.java:2062)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:269)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager$2.handleFileManagerOption(BaseFileManager.java:222)
	at jdk.compiler/com.sun.tools.javac.main.Option.process(Option.java:1138)
	at jdk.compiler/com.sun.tools.javac.main.Option.handleOption(Option.java:1086)
	at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(BaseFileManager.java:232)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Arguments.java:390)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Arguments.java:347)
	at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Arguments.java:246)
	at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(JavacTool.java:185)
	at DumpPlatformClassPath.dumpJDK9AndNewerBootClassPath(DumpPlatformClassPath.java:106)
	at DumpPlatformClassPath.main(DumpPlatformClassPath.java:67)
Target //:ProjectRunner failed to build
INFO: Elapsed time: 15.274s, Critical Path: 1.56s
INFO: 6 processes: 5 internal, 1 darwin-sandbox.
FAILED: Build did NOT complete successfully

@comius
Copy link
Contributor

comius commented May 24, 2022

JDK (not Bazel) checks presence of lib/jrt-fs.jar and/or modules in the JDK installation in Locations$SystemModulesLocationHandler.update(Locations.java:1853)

Based on your output:

ls $(echo $JAVA_HOME)
INSTALL_RECEIPT.json	LICENSE			README			bin			include			libexec			share

they are not there.

Please try with another JDK installation. Others have reported that there are issues with homebrew installation

@comius comius added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) and removed untriaged labels May 24, 2022
@comius comius changed the title Unable to build Java example on m1 mac Unable to build Java example using homebrew May 24, 2022
@comius
Copy link
Contributor

comius commented May 27, 2022

The error reporting could be improved by catching IllegalArgumentException in PlatformClasspath implementation and reporting more precisely what happened.

@comius comius added P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) labels May 27, 2022
@bhushan-helloFresh
Copy link

I faced the same issue (using Mac M1)
Fixed by changing JDK to Azul (https://www.azul.com/downloads/?version=java-11-lts&os=macos&architecture=arm-64-bit&package=jdk).

aiuto pushed a commit to aiuto/bazel that referenced this issue Oct 12, 2022
When JavacTools#create throws IllegalArgumentException, the likely cause is that the configured Java runtime is not a JDK or missing files, as is known to be the case with Homebrew installations. Rather than fail with a cryptic stack trace that only mentions `external/local_jdk`, print a descriptive error with the resolved path of the configured runtime's home directory.

Fixes bazelbuild#15452

Closes bazelbuild#16346.

PiperOrigin-RevId: 477708308
Change-Id: Ibe28a9d5debe633d1dadc0d4638da25fd324c5a6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants