mpdude commented on PR #4765:
URL: https://github.com/apache/solr/pull/4765#issuecomment-5410991527

   I haven't actually run the changed script against different Java/JVM 
versions since I don't have them at hand.
   
   However, AI researched a few typical `-version` outputs for me, and here is 
a bash script that verifies the updated `grep`/`awk` expression against those 
patterns.
   
   Does that help?
   
   ```sh
   #!/bin/bash
   # Standalone test for the JAVA_VER_NUM extraction logic in solr/bin/solr 
(line ~178).
   # Run: bash test-java-version-parsing.sh
   
   set -u
   
   extract() {
     echo "$1" | grep -v '_OPTIONS' | awk -F '"' '/ version "/ {print $2; 
exit}' | sed -e's/^1\.//' | sed -e's/[._-].*$//'
   }
   
   pass=0
   fail=0
   
   check() {
     local desc="$1" input="$2" expected="$3"
     local actual
     actual=$(extract "$input")
     if [[ "$actual" == "$expected" ]]; then
       printf 'PASS  %-55s got %s\n' "$desc" "$actual"
       pass=$((pass+1))
     else
       printf 'FAIL  %-55s expected %s, got "%s"\n' "$desc" "$expected" 
"$actual"
       fail=$((fail+1))
     fi
   }
   
   check "Java 8, old 1.x scheme" \
   'java version "1.8.0_412"
   Java(TM) SE Runtime Environment (build 1.8.0_412-b08)
   Java HotSpot(TM) 64-Bit Server VM (build 25.412-b08, mixed mode)' \
   "8"
   
   check "Java 11 OpenJDK (Temurin)" \
   'openjdk version "11.0.24" 2024-07-16
   OpenJDK Runtime Environment Temurin-11.0.24+8 (build 11.0.24+8)
   OpenJDK 64-Bit Server VM Temurin-11.0.24+8 (build 11.0.24+8, mixed mode)' \
   "11"
   
   check "Java 17 IBM Semeru/OpenJ9 + JDK_JAVA_OPTIONS noise line" \
   'picked up JDK_JAVA_OPTIONS: -Xshare:off
   openjdk version "17.0.11" 2024-04-16
   IBM Semeru Runtime Open Edition 17.0.11.0 (build 17.0.11+9)
   Eclipse OpenJ9 VM 17.0.11.0 (build openj9-0.44.0, JRE 17 Linux amd64-64-Bit 
Compressed References 20240416_547)' \
   "17"
   
   check "Java 21 OpenJDK (Temurin, LTS)" \
   'openjdk version "21.0.4" 2024-07-16 LTS
   OpenJDK Runtime Environment Temurin-21.0.4+7 (build 21.0.4+7-LTS)
   OpenJDK 64-Bit Server VM Temurin-21.0.4+7 (build 21.0.4+7-LTS, mixed mode, 
sharing)' \
   "21"
   
   check "Java 21 GraalVM" \
   'java version "21.0.2" 2024-01-16
   Java(TM) SE Runtime Environment Oracle GraalVM 21.0.2+13.1 (build 
21.0.2+13-jvmci-23.1-b30)
   Java HotSpot(TM) 64-Bit Server VM Oracle GraalVM 21.0.2+13.1 (build 
21.0.2+13-jvmci-23.1-b30, mixed mode, sharing)' \
   "21"
   
   check "Java 25, SVE warning line BEFORE version line (this PR's bug report)" 
\
   'OpenJDK 64-Bit Server VM warning: Unable to get SVE vector length on this 
system. Disabling SVE. Specify -XX:UseSVE=0 to shun this warning.
   openjdk version "25.0.3" 2026-04-21 LTS
   OpenJDK Runtime Environment Temurin-25.0.3+9 (build 25.0.3+9-LTS)
   OpenJDK 64-Bit Server VM Temurin-25.0.3+9 (build 25.0.3+9-LTS, mixed mode, 
sharing)' \
   "25"
   
   echo
   echo "For comparison, the OLD logic (head -1 | awk '/version/') on the 
SVE-warning case:"
   old_result=$(echo 'OpenJDK 64-Bit Server VM warning: Unable to get SVE 
vector length on this system. Disabling SVE. Specify -XX:UseSVE=0 to shun this 
warning.
   openjdk version "25.0.3" 2026-04-21 LTS' | grep -v '_OPTIONS' | head -1 | 
awk -F '"' '/version/ {print $2}' | sed -e's/^1\.//' | sed -e's/[._-].*$//')
   echo "  -> \"${old_result}\" (empty = the reported bug: JAVA_VER_NUM ends up 
blank)"
   
   echo
   echo "$pass passed, $fail failed"
   [[ $fail -eq 0 ]]
   ```
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to