Skip to content

Commit 182f4bd

Browse files
committed
Simplify version parse to a single anchored bash regex (review feedback)
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>
1 parent 55951e2 commit 182f4bd

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

‎server/basedir-includes/oieserver‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ is_valid_java_version() {
136136
return 1
137137
fi
138138

139-
# Extract the major version number. This works for formats like "1.8.0" and "17.0.2".
140-
local major_version
141-
# Select the line with the quoted version string rather than the first line, so a
142-
# "Picked up JAVA_TOOL_OPTIONS:" banner (printed to stderr when JAVA_TOOL_OPTIONS or
143-
# _JAVA_OPTIONS is set) is not mistaken for the version line. See
144-
# OpenIntegrationEngine/engine#523.
145-
major_version=$(echo "$version_output" | grep -E 'version "' | head -n 1 | cut -d '"' -f 2 | cut -d '.' -f 1)
139+
# Extract the major version number by matching the quoted version string (e.g.
140+
# openjdk version "17.0.2"). Matching 'version "' rather than scanning the whole
141+
# output means a "Picked up JAVA_TOOL_OPTIONS:" banner - printed to stderr when
142+
# JAVA_TOOL_OPTIONS or _JAVA_OPTIONS is set - or any other number in the output is
143+
# not mistaken for the version. Works for both "1.8.0" and "17.0.2" formats. See #523.
144+
local major_version=""
145+
[[ "$version_output" =~ version\ \"([0-9]+) ]] && major_version="${BASH_REMATCH[1]}"
146146

147147
# Check if the extracted version is a number and meets the minimum requirement
148148
if [[ "$major_version" =~ ^[0-9]+$ ]] && [[ "$major_version" -ge "$MIN_JAVA_VERSION" ]]; then

0 commit comments

Comments
 (0)