Skip to content

Commit 8e93f5c

Browse files
committed
Improve Temurin JDK version detection
Enhances the setup_java function to attempt a package purge and reinstall if a Temurin JDK is detected but its version cannot be determined. This helps recover from inconsistent or broken JDK installations.
1 parent 838e663 commit 8e93f5c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

misc/tools.func

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2784,12 +2784,19 @@ function setup_java() {
27842784
INSTALLED_VERSION=$(dpkg -l 2>/dev/null | awk '/temurin-.*-jdk/{print $2}' | grep -oP 'temurin-\K[0-9]+' | head -n1 || echo "")
27852785
fi
27862786

2787-
# Validate INSTALLED_VERSION is not empty if matched
2787+
# Validate INSTALLED_VERSION is not empty if JDK package found
27882788
local JDK_COUNT=0
27892789
JDK_COUNT=$(dpkg -l 2>/dev/null | grep -c "temurin-.*-jdk" || true)
27902790
if [[ -z "$INSTALLED_VERSION" && "${JDK_COUNT:-0}" -gt 0 ]]; then
2791-
msg_warn "Found Temurin JDK but cannot determine version"
2792-
INSTALLED_VERSION="0"
2791+
msg_warn "Found Temurin JDK but cannot determine version - attempting reinstall"
2792+
# Try to get actual package name for purge
2793+
local OLD_PACKAGE
2794+
OLD_PACKAGE=$(dpkg -l 2>/dev/null | awk '/temurin-.*-jdk/{print $2}' | head -n1 || echo "")
2795+
if [[ -n "$OLD_PACKAGE" ]]; then
2796+
msg_info "Removing existing package: $OLD_PACKAGE"
2797+
$STD apt purge -y "$OLD_PACKAGE" || true
2798+
fi
2799+
INSTALLED_VERSION="" # Reset to trigger fresh install
27932800
fi
27942801

27952802
# Scenario 1: Already at correct version

0 commit comments

Comments
 (0)