halcyon / asdf-java

A Java plugin for asdf-vm.
MIT License
466 stars 86 forks source link

set-java-home not properly detecting symlinks #150

Open sirianni opened 3 years ago

sirianni commented 3 years ago

https://github.com/halcyon/asdf-java/pull/114 seems to have broken symlink handling for JAVA_HOME resolution on Linux. The cd -P workaround does not handle when the file itself is symlinked vs. the directory.

You can see that realpath /usr/bin/java works, but the cd -P workaround for OSX returns the incorrect path.

$ asdf which java
/usr/bin/java

$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 37 May 16  2020 /usr/bin/java -> /usr/lib/jvm/default-runtime/bin/java*

$ realpath /usr/bin/java
/usr/lib/jvm/java-11-openjdk/bin/java

$ echo $( cd -P "$( dirname /usr/bin/java )" && pwd )
/usr/bin

Here is set-java-home.zsh run with debugging

+asdf_update_java_home:1> local java_path
+asdf_update_java_home:2> java_path=
+asdf_update_java_home:2> asdf which java
+asdf_update_java_home:2> java_path=/usr/bin/java 
+asdf_update_java_home:3> [[ -n /usr/bin/java ]]
+asdf_update_java_home:4> export JAVA_HOME
+asdf_update_java_home:5> JAVA_HOME=
+asdf_update_java_home:5> absolute_dir_path /usr/bin/java
+absolute_dir_path:1> local absolute_path
+absolute_dir_path:2> absolute_path=
+absolute_dir_path:2> dirname /usr/bin/java
+absolute_dir_path:2> absolute_path=
+absolute_dir_path:2> cd -P /usr/bin
+absolute_dir_path:2> pwd
+absolute_dir_path:2> absolute_path=/usr/bin 
+absolute_dir_path:3> echo /usr/bin
+asdf_update_java_home:5> JAVA_HOME=
+asdf_update_java_home:5> dirname /usr/bin
+asdf_update_java_home:5> JAVA_HOME=/usr