You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
asdf which java writes error message to stdout instead of stderr #266
asdf which java outputs its error message to stdout instead of stderr when no java version is configured:
$ java_path="$(asdf which java 2>/dev/null)"
$ echo"java_path='$java_path'"
java_path='unexpected error: no versions set for java'
Impact
set-java-home.zsh captures this error string into java_path via $(). Because the string is non-empty, the [[ -n "${java_path}" ]] guard passes and the hook proceeds to compute:
The :A modifier in zsh resolves relative paths against $PWD, so "unexpected error: no versions set for java" (no leading /) becomes $PWD/unexpected error: no versions set for java. Two dirname calls then strip the last two components, leaving:
JAVA_HOME = dirname(dirname($PWD))
The result is a silently wrong, directory-dependent JAVA_HOME — it changes every time you cd:
~
❯ grails -version
ERROR: JAVA_HOME is set to an invalid directory: /Users
~/src/dotfiles
❯ grails -version
ERROR: JAVA_HOME is set to an invalid directory: /Users/jason/src
Expected behavior
Error messages should go to stderr so that $() captures only meaningful output.
Activity