armorbreak001 opened a new pull request, #416:
URL: https://github.com/apache/maven-wrapper/pull/416
## Problem
`only-mvnw.cmd` crashes with **"Cannot index into a null array"** when
running under the Local System account in a 32-bit process (typical for Jenkins
Agents running as a Windows Service).
The root cause is on the symlink-resolution line:
```powershell
if ((Get-Item -Path $MAVEN_M2_PATH -Force).Target[0] -eq $null)
```
On the System Profile `.m2` path
(`C:\WINDOWS\system32\config\systemprofile\.m2`) accessed from a 32-bit
process, `Get-Item.Target` returns strictly `$null` (not an empty collection).
Indexing `[0]` on `$null` throws `RuntimeException`.
## Fix
Cache the `Get-Item` result and check that the `Target` property exists
**and** is non-null before attempting to index it. When `Target` is
unavailable, fall through to the standard (non-symlink) path — which is the
correct behavior for non-symlinked directories.
**Before:**
```powershell
if ((Get-Item -Path $MAVEN_M2_PATH -Force).Target[0] -eq $null) {
...
}
```
**After:**
```powershell
$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 = "$MAVEN_M2_PATH/wrapper/dists"
}
```
Also swapped the branch order so the common case (non-symlink) is the `else`
branch, avoiding unnecessary property inspection for the majority of users.
Fixes #395
--
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]