Skip to content

Commit

Permalink
[MWRAPPER-112] Detection of JAVA_HOME fails due to bad quoting
Browse files Browse the repository at this point in the history
On a standard Ubuntu 20.04 Java installation (openjdk-17-jdk APT package, /usr/bin/javac linked to /usr/lib/jvm/java-17-openjdk-amd64/bin/javac via the update-alternatives system, no JAVA_HOME set), Maven Wrapper 3.2.0 prints this warning on each invocation:
> Warning: JAVA_HOME environment variable is not set.

This is caused by excessive quoting that adds literal double quotes to the resolution of javaHome and javaExecutable. (Some nearby invocations of "expr" use correct quoting, but several are wrong. There might have been obscure bugs and someone thought that more quoting is better. That code has been in the codebase since the beginning, taken over from the gradlew wrapper (which had the shell wrappers completely rewritten; there are no remnants of this code found there any longer).) With the literal quotes, the file system lookup fails to resolve the directory, and the auto-detection of JAVA_HOME fails, causing that warning.
  • Loading branch information
inkarkat committed Jun 13, 2023
1 parent 2a0a17c commit db5d9d1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions maven-wrapper-distribution/src/resources/mvnw
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ fi

if [ -z "$JAVA_HOME" ]; then
javaExecutable="$(which javac)"
if [ -n "$javaExecutable" ] && ! [ "$(expr "\"$javaExecutable\"" : '\([^ ]*\)')" = "no" ]; then
if [ -n "$javaExecutable" ] && ! [ "$(expr "$javaExecutable" : '\([^ ]*\)')" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=$(which readlink)
if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then
if $darwin ; then
javaHome="$(dirname "\"$javaExecutable\"")"
javaExecutable="$(cd "\"$javaHome\"" && pwd -P)/javac"
javaHome="$(dirname "$javaExecutable")"
javaExecutable="$(cd "$javaHome" && pwd -P)/javac"
else
javaExecutable="$(readlink -f "\"$javaExecutable\"")"
javaExecutable="$(readlink -f "$javaExecutable")"
fi
javaHome="$(dirname "\"$javaExecutable\"")"
javaHome="$(dirname "$javaExecutable")"
javaHome=$(expr "$javaHome" : '\(.*\)/bin')
JAVA_HOME="$javaHome"
export JAVA_HOME
Expand Down

0 comments on commit db5d9d1

Please sign in to comment.