gnodet-bot commented on code in PR #13652:
URL: https://github.com/apache/maven/pull/13652#discussion_r4347308147


##########
apache-maven/src/assembly/maven/bin/mvn.cmd:
##########
@@ -336,17 +336,21 @@ if exist "%JVM_CONFIG_TEMP%" (
     echo [DEBUG] Temp file contents:
     type "%JVM_CONFIG_TEMP%"
   )
+  setlocal EnableDelayedExpansion
   set /p JVM_CONFIG_MAVEN_OPTS=<"%JVM_CONFIG_TEMP%" 2>nul
   rem Retry once after a brief delay if the read returned empty (Windows 
Defender file lock).
   rem Note: use string comparison instead of 'if not defined' because 'set 
JVM_CONFIG_MAVEN_OPTS='
   rem (empty assignment) counts as defined, so 'if not defined' would never 
trigger the retry.
-  if "%JVM_CONFIG_MAVEN_OPTS%"=="" (
+  rem Note: use delayed expansion (!VAR! instead of %VAR%) because cmd.exe 
expands %VAR% at
+  rem parse time for the entire compound block, before 'set /p' above has run 
at runtime.
+  if "!JVM_CONFIG_MAVEN_OPTS!"=="" (
     if defined MAVEN_DEBUG_SCRIPT (
       echo [DEBUG] First read returned empty, retrying after delay...
     )
     ping -n 2 127.0.0.1 >nul 2>nul
     set /p JVM_CONFIG_MAVEN_OPTS=<"%JVM_CONFIG_TEMP%" 2>nul
   )
+  endlocal & set "JVM_CONFIG_MAVEN_OPTS=!JVM_CONFIG_MAVEN_OPTS!"

Review Comment:
   ⚠️ **Bug:** After `endlocal`, delayed expansion is disabled (the outer 
`@setlocal` at line 53 does not enable it). `!JVM_CONFIG_MAVEN_OPTS!` on this 
line is therefore treated as a literal string — not expanded — and 
`JVM_CONFIG_MAVEN_OPTS` is exported as `!JVM_CONFIG_MAVEN_OPTS!`.
   
   Use the `FOR /F` workaround to capture the value while still inside the 
delayed-expansion scope:
   
   ```suggestion
     for /f "delims=" %%V in ("!JVM_CONFIG_MAVEN_OPTS!") do (
       endlocal
       set "JVM_CONFIG_MAVEN_OPTS=%%V"
     )
   ```



-- 
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]

Reply via email to