-
Notifications
You must be signed in to change notification settings - Fork 70
Description
Affected version
3.3.3
Bug description
Description
In mvnw.cmd, the logic introduced by PR #143 to handle symlinks attempts to access an array index on the Target property without checking if it is null.
mvnw.cmd fails immediately upon execution with a "Cannot index into a null array" error. This issue specifically occurs when the script runs under the Local System account in a 32-bit process (typical for Jenkins Agents running as a Windows Service), where the default .m2 home resolves to the System Profile directory.
Error Log
icm : Cannot index into a null array
At line:1 char:81
+ ... 'mvnw.cmd'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-Command], RuntimeException
+ FullyQualifiedErrorId : NullArray,Microsoft.PowerShell.Commands.InvokeCommandCommand
Environment
- OS: Windows Server 2022
- Process Architecture: 32-bit (x86)
- User:
NT AUTHORITY\SYSTEM - Target Path:
C:\WINDOWS\system32\config\systemprofile\.m2 - PowerShell: 5.1
Root Cause Analysis
The script contains the following logic to handle symlinks:
if ((Get-Item $MAVEN_M2_PATH).Target[0] -eq $null) { ... }We verified the behavior of the Target property on this specific environment:
- Standard Paths (e.g., Workspace drive): The
Targetproperty returns an empty collection. Accessing[0]returns$nullsafely (in PowerShell 5.1). - System Profile Path (
.m2): When accessing the.m2directory in the System Profile from a 32-bit process, theTargetproperty returns strictly$null.
Since mvnw.cmd defaults MAVEN_M2_PATH to the user home (System Profile), the script attempts to access index [0] on $null, causing a fatal RuntimeException.
Verification Code & Result
We ran the following diagnostic inside the failing Jenkins environment, specifically targeting the .m2 directory:
$basePath = $env:USERPROFILE
$m2Path = Join-Path $basePath ".m2"
# Ensure .m2 exists for testing
if (-not (Test-Path -Path $m2Path)) { New-Item -Path $m2Path -ItemType Directory | Out-Null }
$prop = (Get-Item $m2Path).Target
Write-Host "Testing Path: $m2Path"
Write-Host "Is Null? : " ($prop -eq $null)
try { $null = $prop[0]; Write-Host "Safe" } catch { Write-Host "CRASH" }Output:
Testing Path: C:\WINDOWS\system32\config\systemprofile\.m2
Is Null? : True
CRASH
Proposed Fix
The script must check if the Target property is not null before attempting to index it.
Suggested Change:
$m2Item = Get-Item $MAVEN_M2_PATH
# Safe check: Ensure property exists and is not null before indexing
if ($m2Item.PSObject.Properties['Target'] -ne $null -and $m2Item.Target -ne $null) {
$MAVEN_WRAPPER_DISTS = $m2Item.Target + "/wrapper/dists"
} else {
$MAVEN_WRAPPER_DISTS = "$MAVEN_M2_PATH/wrapper/dists"
}