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


##########
impl/maven-logging/src/main/java/org/apache/maven/slf4j/MavenSimpleLogger.java:
##########
@@ -116,24 +160,32 @@ protected void printStackTrace(Throwable t, 
Consumer<String> stream, String pref
             stream.accept(builder.toString());
             builder.setLength(0);
         }
-        for (Throwable se : t.getSuppressed()) {
-            writeThrowable(se, stream, "Suppressed", prefix + "    ");
-        }
-        Throwable cause = t.getCause();
-        if (cause != null && t != cause) {
-            writeThrowable(cause, stream, "Caused by", prefix);
+        if (depth < MAX_THROWABLE_DEPTH) {
+            for (Throwable se : t.getSuppressed()) {
+                writeThrowable(se, stream, "Suppressed", prefix + "    ", 
depth + 1);
+            }
+            Throwable cause = t.getCause();
+            if (cause != null && t != cause) {
+                writeThrowable(cause, stream, "Caused by", prefix, depth + 1);
+            }
+        } else {
+            stream.accept(prefix + "    [...cause/suppressed chain truncated 
at depth " + MAX_THROWABLE_DEPTH + "]");

Review Comment:
   **[Low] No test for the truncation path.**
   
   The `depth >= MAX_THROWABLE_DEPTH` branch (the `else` clause above) is new 
code with no regression guard. `MavenSimpleLoggerTest` already covers nested 
exceptions via `writeThrowable_withSuppressedAndCauses`, so a companion test is 
straightforward:
   
   ```java
   @Test
   void writeThrowable_truncatesAtMaxDepth() {
       // Build a chain of depth 21 to trigger truncation
       RuntimeException root = new RuntimeException("root");
       RuntimeException current = root;
       for (int i = 0; i < 21; i++) {
           RuntimeException next = new RuntimeException("cause-" + i);
           current.initCause(next);
           current = next;
       }
   
       List<String> lines = new ArrayList<>();
       new MavenSimpleLogger("test").writeThrowable(root, lines::add);
   
       assertTrue(lines.stream().anyMatch(l -> l.contains("truncated at 
depth")),
           "Expected truncation notice after depth 20");
   }
   ```
   
   The fix logic itself is correct — `depth + 1` is propagated through the 
`private` call chain and the guard fires properly at `depth == 
MAX_THROWABLE_DEPTH`.



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