You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "armorbreak001 (via GitHub)" <gi...@apache.org> on 2026/04/21 04:35:44 UTC

[PR] fix(wrapper): guard against null Target property in only-mvnw.cmd [maven-wrapper]

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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(wrapper): guard against null Target property in only-mvnw.cmd [maven-wrapper]

Posted by "slachiewicz (via GitHub)" <gi...@apache.org>.
slachiewicz commented on PR #416:
URL: https://github.com/apache/maven-wrapper/pull/416#issuecomment-4296700152

   same as #405


-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(wrapper): guard against null Target property in only-mvnw.cmd [maven-wrapper]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #416:
URL: https://github.com/apache/maven-wrapper/pull/416#discussion_r3124403832


##########
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) {

Review Comment:
   The new symlink detection condition will mis-handle the common non-symlink case where `Get-Item ... .Target` is an empty collection (not `$null`). In that scenario `$m2Item.Target -ne $null` is true, but `$m2Item.Target[0]` is `$null`, causing `$MAVEN_WRAPPER_DISTS` to become just `"/wrapper/dists"` (relative path) instead of using `$MAVEN_M2_PATH`. Update the condition to also require a non-null first target (or a non-empty Target collection) before using `Target[0]`; otherwise fall back to `$MAVEN_M2_PATH/wrapper/dists`.
   ```suggestion
   if ($m2Item.PSObject.Properties['Target'] -ne $null -and $m2Item.Target -ne $null -and $m2Item.Target[0] -ne $null) {
   ```



-- 
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: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org