You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "ZhongRuoyu (via GitHub)" <gi...@apache.org> on 2023/03/29 09:41:52 UTC

[GitHub] [solr] ZhongRuoyu commented on a diff in pull request #1502: SOLR-16721 Java version detection fails when `_JAVA_OPTIONS` is set

ZhongRuoyu commented on code in PR #1502:
URL: https://github.com/apache/solr/pull/1502#discussion_r1151667097


##########
solr/bin/solr:
##########
@@ -163,7 +163,7 @@ if [[ $? -ne 0 ]] ; then
   echo >&2 "${PATH}"
   exit 1
 else
-  JAVA_VER_NUM=$(echo "$JAVA_VER" | head -1 | awk -F '"' '/version/ {print $2}' | sed -e's/^1\.//' | sed -e's/[._-].*$//')
+  JAVA_VER_NUM=$(echo "$JAVA_VER" | awk -F '"' '/version/ {print $2}' | sed -e's/^1\.//' | sed -e's/[._-].*$//')

Review Comment:
   To make the patch more robust, I suggest this:
   
   ```suggestion
     JAVA_VER_NUM=$(echo "$JAVA_VER" | grep -v '_JAVA_OPTIONS' | awk -F '"' '/version/ {print $2}' | sed -e's/^1\.//' | sed -e's/[._-].*$//')
   ```
   
   This prevents matching any occurrence of `version` found in `_JAVA_OPTIONS`:
   
   ```console
   $ export _JAVA_OPTIONS='-Dmy.package.version="123"'
   $ JAVA_VER=$(java -version 2>&1)
   $ echo "$JAVA_VER" | awk -F '"' '/version/ {print $2}' | sed -e's/^1\.//' | sed -e's/[._-].*$//'
   123
   19
   $ echo "$JAVA_VER" | grep -v '_JAVA_OPTIONS' | awk -F '"' '/version/ {print $2}' | sed -e's/^1\.//' | sed -e's/[._-].*$//'
   19
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org