Big Sur doesn't track JAVA_HOME when running commands from the JDK

Previous versions of macOS use the current value of the JAVA_HOME environment variable to launch the appropriate version of any commands from the JDK bin folder. This was presumably handled by some magic in the JDK commands that are installed in /usr/bin.
On Big Sur beta 7 I am no longer seeing this behaviour. I always get the latest installed version of the JDK command regardless of what I set JAVA_HOME to.

I usually run a script to set JAVA_HOME based on the output of
Code Block
/usr/libexec/java_home -v ???

(where ??? is related with the JDK version). The java_home command is working as expected and I am sure that the JAVA_HOME environment variable is correctly set.

I've submitted a report with Feedback Assistant, but I wonder if others can confirm this is a reproducible problem. Is there a workaround?
I can confirm this is an issue on MacOS 11 Beta 8 (as well).

Bottom Line: The delegate java commands use JAVAVERSION to route to the correct JDK, not JAVAHOME. So, Set JAVA_VERSION="1.8".

Set JAVA_HOME too, but that's for other tools.

The binaries /usr/bin/java and /usr/bin/javac (etc) are all the same binary which (I'm guessing) launch the correct command based on examining its first parameter and (as of Big Sur) the JAVA_VERSION environment variable.

You can set JAVA_LAUNCHER_VERBOSE=1 to get output its assumptions about paths and versions.

Helper

For anyone reading this who is NOT a super expert on all this JDK stuff, you can add helpers to your shell init: some variation on:

Code Block
switch_java() {
export JAVA_HOME=$(/usr/libexec/java_home -v $1)
export JAVA_VERSION="$1"
echo "JAVA_HOME: ${JAVA_HOME}"
echo "JAVA_VERSION: ${JAVA_VERSION}". #### WORKAROUND ####
java -version
}
java8() { switch_java 1.8 }
java11() { switch_java 11 }

NOTE: Setting JAVA_VERSION as well as JAVA_HOME.

Code Block
$ java8
JAVA_HOME: /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home
JAVA_VERSION: 1.8
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (Zulu 8.48.0.53-CA-macosx) (build 1.8.0_265-b11)
OpenJDK 64-Bit Server VM (Zulu 8.48.0.53-CA-macosx) (build 25.265-b11, mixed mode)
$ java11
JAVA_HOME: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
JAVA_VERSION: 11
openjdk version "11.0.6" 2020-01-14 LTS
OpenJDK Runtime Environment Zulu11.37+17-CA (build 11.0.6+10-LTS)
OpenJDK 64-Bit Server VM Zulu11.37+17-CA (build 11.0.6+10-LTS, mixed mode)

and so on.


Big Sur doesn't track JAVA_HOME when running commands from the JDK
 
 
Q