From ebf184b6a413a7cca4f18037afd42246c7b8fa36 Mon Sep 17 00:00:00 2001 From: armorbreak001 Date: Tue, 21 Apr 2026 12:35:31 +0800 Subject: [PATCH] fix(wrapper): guard against null Target property in only-mvnw.cmd When only-mvnw.cmd runs under the Local System account in a 32-bit process (e.g. Jenkins Agent as Windows Service), Get-Item returns $null for the Target property on the System Profile .m2 path. Accessing [0] on $null causes a fatal RuntimeException. Check that the Target property exists and is non-null before attempting to index it. Falls back to the non-symlink path when Target is unavailable. Fixes #395 --- maven-wrapper-distribution/src/resources/only-mvnw.cmd | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/maven-wrapper-distribution/src/resources/only-mvnw.cmd b/maven-wrapper-distribution/src/resources/only-mvnw.cmd index fd5f5ccd..98152505 100644 --- a/maven-wrapper-distribution/src/resources/only-mvnw.cmd +++ b/maven-wrapper-distribution/src/resources/only-mvnw.cmd @@ -89,10 +89,11 @@ if (-not (Test-Path -Path $MAVEN_M2_PATH)) { } $MAVEN_WRAPPER_DISTS = $null -if ((Get-Item -Path $MAVEN_M2_PATH -Force).Target[0] -eq $null) { - $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" +$m2Item = Get-Item -Path $MAVEN_M2_PATH -Force +if ($m2Item.PSObject.Properties['Target'] -ne $null -and $m2Item.Target -ne $null) { + $MAVEN_WRAPPER_DISTS = $m2Item.Target[0] + "/wrapper/dists" } else { - $MAVEN_WRAPPER_DISTS = (Get-Item -Path $MAVEN_M2_PATH -Force).Target[0] + "/wrapper/dists" + $MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists" } $MAVEN_HOME_PARENT = "$MAVEN_WRAPPER_DISTS/$distributionUrlNameMain"