Repository navigation
Conversation
|
Can we simplify? We're doing a lot of pipelining here - perhaps an option on java or STDERR vs STDOUT. Or just a vanilla bash regex? For example: #!/bin/bash
if [[ $(java -version 2>&1) =~ ([0-9]+(\.[0-9_]+)+) ]]; then
version="${BASH_REMATCH[1]}"
echo "Java Version: $version"
fiSeems to work with: Also: please make sure to sign your commit with a DCO. |
|
Ran this branch under eclipse-temurin:17: it starts with JAVA_TOOL_OPTIONS and with _JAVA_OPTIONS set, and jcmd shows the option reached the JVM. Main's script refuses with the same variable set. The fix works. @mgaffigan on the regex: unanchored, it takes the first number.number in the output, and the banner comes first. With JAVA_TOOL_OPTIONS=-XX:MaxRAMPercentage=75.0 it reads "75" on Java 17 and on Java 11, so an old Java passes the check. With -Dotel.resource.attributes=service.version=1.4.2 it reads "1" and the launcher refuses Java 17 (tried it in the script). Your example has no dot, which is why it passed. Anchoring on the version line keeps the one-liner and passed everything I tried: @iacsha that plus the DCO sign-off (git commit --amend -s --no-edit, then git push --force-with-lease) and I'm good. Co-authored with Claude Code. |
It was an example of methodology. Not something expected to be usable without edits. |
|
Thanks both. @pacmano1 — appreciate the verification under both @mgaffigan — agreed, simplified. Dropped the pipeline for a single anchored bash regex (no local major_version=""
[[ "$version_output" =~ version\ \"([0-9]+) ]] && major_version="${BASH_REMATCH[1]}"On the other two ideas: splitting streams doesn't help, because the
|
…ionEngine#523) is_valid_java_version parsed java -version with head -n 1, so the Picked up JAVA_TOOL_OPTIONS banner printed to stderr was read instead of the version line and every candidate Java was rejected. Select the line containing the quoted version string before cutting. Signed-off-by: iacsha <122627209+iacsha@users.noreply.github.com>
Replace the grep/head/cut pipeline with a bash regex anchored on the quoted version string. Anchoring on version " keeps the Picked up JAVA_TOOL_OPTIONS banner (and any other number in the output) from being read as the version. Signed-off-by: iacsha <122627209+iacsha@users.noreply.github.com>
1ae8e94 to
182f4bd
Compare
Find Java correctly when JAVA_TOOL_OPTIONS is set (fixes #523)
Problem
is_valid_java_version()inoieserverreadsjava -versionand takes the first line:When
JAVA_TOOL_OPTIONS(or_JAVA_OPTIONS) is set, the JVM prints aPicked up JAVA_TOOL_OPTIONS: …banner to stderr before the version line.head -n 1thenreads the banner instead of
openjdk version "17.0.x",major_versionis not numeric,every candidate Java is rejected, and the server refuses to start.
Fix
Select the line that actually contains the quoted version string before cutting, so the
banner (or any other leading stderr noise) is ignored:
major_version=$(echo "$version_output" | grep -E 'version "' | head -n 1 | cut -d '"' -f 2 | cut -d '.' -f 1)One line changed in
server/basedir-includes/oieserver.Verification
java -versionunder a JDK 17 runtime, with and withoutJAVA_TOOL_OPTIONS:The banner case now parses correctly, and the normal case is unchanged.