This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch maven-4.0.x
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/maven-4.0.x by this push:
     new 5f24cba573 Bug: when raw-streams are used, ensure system streams are 
set up (#11303) (#11310)
5f24cba573 is described below

commit 5f24cba5730d8b47e46429b507925eda3d0f8187
Author: Tamas Cservenak <[email protected]>
AuthorDate: Tue Oct 21 14:19:42 2025 +0200

    Bug: when raw-streams are used, ensure system streams are set up (#11303) 
(#11310)
    
    When `--raw-streams` is used (especially when combined with options like 
`--quiet` and `-DforceStdout`) there is no guarantee that anything touches 
terminal. Hence, in case of embedded executor it is quite possible that 
cached/warm code arrives quickly at the place that would do system out 
**before** the thread with `FastTerminal` finishes system install.
    
    In other words, when `--raw-streams` are used, we cannot guarantee that 
system streams are already properly set up. This PR changes that, and makes 
sure (by triggering a dummy call to terminal), at the cost of "jline3 install 
lag" for CLI invocation. OTOH, this lag in case of embedded executors does not 
exists (it exists only on first invocation).
    
    My suspicion that this is the cause of IT instability issues, when Verifier 
used Toolbox output ends up on Surefire stdout and not on "grabbed" output, as 
simply streams are not yet set up properly. Also, this usually happens "around 
the second half" of ITs, when cached and warmed up embedded instance is already 
uber optimized.
    
    Backport of bb94de05501d2b9744d6e7db249318f07b633a5d
---
 .../main/java/org/apache/maven/cling/invoker/LookupInvoker.java   | 7 +++++++
 .../org/apache/maven/cling/executor/internal/ToolboxTool.java     | 8 +++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git 
a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
 
b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
index 0d5e5caa64..50448a8ade 100644
--- 
a/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
+++ 
b/impl/maven-cli/src/main/java/org/apache/maven/cling/invoker/LookupInvoker.java
@@ -323,6 +323,13 @@ protected final void createTerminal(C context) {
             context.terminal = MessageUtils.getTerminal();
             context.closeables.add(MessageUtils::systemUninstall);
             MessageUtils.registerShutdownHook(); // safety belt
+
+            // when we use embedded executor AND --raw-streams, we must ENSURE 
streams are properly set up
+            if (context.invokerRequest.embedded()
+                    && context.options().rawStreams().orElse(false)) {
+                // to trigger FastTerminal; with raw-streams we must do this 
ASAP (to have system in/out/err set up)
+                context.terminal.getName();
+            }
         } else {
             doConfigureWithTerminal(context, context.terminal);
         }
diff --git 
a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/ToolboxTool.java
 
b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/ToolboxTool.java
index ebdd3ac2a5..ad2569a849 100644
--- 
a/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/ToolboxTool.java
+++ 
b/impl/maven-executor/src/main/java/org/apache/maven/cling/executor/internal/ToolboxTool.java
@@ -159,9 +159,11 @@ private String validateOutput(boolean shave, 
ByteArrayOutputStream stdout, ByteA
             result = result.replace("\n", "").replace("\r", "");
         }
         // sanity checks: stderr has any OR result is empty string (no method 
should emit empty string)
-        if (stderr.size() > 0 || result.trim().isEmpty()) {
-            System.err.println(
-                    "Unexpected stdout[" + stdout.size() + "]=" + stdout + "; 
stderr[" + stderr.size() + "]=" + stderr);
+        if (result.trim().isEmpty()) {
+            // see bug https://github.com/apache/maven/pull/11303 Fail in this 
case
+            // tl;dr We NEVER expect empty string as output from this tool; so 
fail here instead to chase ghosts
+            throw new IllegalStateException("Empty output from Toolbox; 
stdout[" + stdout.size() + "]=" + stdout
+                    + "; stderr[" + stderr.size() + "]=" + stderr);
         }
         return result;
     }

Reply via email to