From 0522377ccd43978bb15338870c37f2701fc2938e Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Tue, 13 Jun 2023 09:28:49 +0200 Subject: [PATCH] [MWRAPPER-112] Detection of JAVA_HOME fails due to bad quoting 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. --- maven-wrapper-distribution/src/resources/mvnw | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/maven-wrapper-distribution/src/resources/mvnw b/maven-wrapper-distribution/src/resources/mvnw index b68cc2b..59ebc2d 100644 --- a/maven-wrapper-distribution/src/resources/mvnw +++ b/maven-wrapper-distribution/src/resources/mvnw @@ -100,17 +100,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