Bazel fails to recognize valid $JAVA_HOME as a JDK on macOS Big Sur
After upgrading to macOS Big Sur, all invocations of bazel output the following and immediately exit:
$ export JAVA_HOME=$(/usr/libexec/java_home -v11)
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
$ bazel build <anything>
WARNING: Ignoring JAVA_HOME, because it must point to a JDK, not a JRE.
FATAL: Could not find system javabase. Ensure JAVA_HOME is set, or javac is on your PATH.
macOS Big Sur
bazel info release?release 3.7.0-homebrew
If I'm reading it correctly, the relevant code appears to be here: https://github.com/bazelbuild/bazel/blob/910079bef2a64b06cc17dd912f97a87298de0b9b/src/main/cpp/blaze_util_darwin.cc#L168-L199
Based on that code, I'd hazard a guess that the access check is failing. My JDK does contain a bin/javac executable, which otherwise appears to be working fine.
There is a workaround, which makes it appear to me as though bazel is just having some issue verifying the JDK pointed to by the environment variable:
bazel --server_javabase=$JAVA_HOME build <anything>
# works fine
@susinmotion looks like this is about core bazel config, not sure it belongs here? not sure how we're treating the issues from this repo though
Thanks for the quick response, I'll bring it back to Bazel core!
Speaking of which, do you have the capability to transfer issues to bazelbuild/bazel too? That seems like a pretty good route if issues incorrectly get sent there.
The working heuristic is for Apple-related Starlark issues to go here, and Apple-related Java issues to stay in Bazel core. I did not follow this heuristic correctly!
Looks like I can only transfer to the repos I have write access to

good to know, thanks for checking that out. So, if you encounter another misplaced issue, what you did is great--if you cc a Bazel team member we can transfer it accordingly!
@oquenchil, the team-Apple label is deprecated. I'm going to return this issue to team-Rules-CPP, since issues pertaining to core Bazel cc rules + Mac belong in that component. Please feel free to move it elsewhere if that description doesn't apply.
More data is needed, we can't reproduce the issue.
@philwo Bazel worked fine on Big Sur so far and setting JAVA_HOME to different paths worked fine, too.
Did a little bit more debugging this morning and found some more info that I think is pointing to the source of my problem:
brew edited the homebrew bazel formula to omit the openjdk11 dependency, since I didn't want homebrew installing a different/additional version of openjdk than the one I already had on my system.So it seems like my issue is due to the fact that the homebrew version of the bazel installation is being picky about the specific location of the JDK. I'm not sure if this would be considered a bug with the homebrew bazel formula or WAI (also not sure if that is managed by the bazel team or homebrew team), but my issue is resolved by just using the non-homebrew installation. If this is WAI as far as the homebrew installation is concerned, feel free to close, otherwise I can re-file this as a homebrew issue.
Thanks!