gnodet commented on code in PR #3590:
URL: https://github.com/apache/maven-surefire/pull/3590#discussion_r4792306454
##########
surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java:
##########
@@ -207,11 +207,24 @@ private static String causeToString(Throwable cause,
StackTraceFilter filter) {
while (cause != null) {
resp.append("Caused by: ");
resp.append(toString(cause, asList(cause.getStackTrace()),
filter));
+ resp.append(suppressedToString(cause, filter));
cause = cause.getCause();
}
return resp.toString();
}
+ // SUREFIRE-1772
+ private static String suppressedToString(Throwable t, StackTraceFilter
filter) {
Review Comment:
**Good implementation of nested suppressed exceptions**
The recursive structure here correctly handles:
1. Suppressed exceptions with their own suppressed exceptions (line 222)
2. Suppressed exceptions with cause chains (line 223)
This matches Java's standard printStackTrace behavior and creates proper
mutual recursion with `causeToString`. The recursion is safe because Java
prevents exception cycles (a throwable cannot be its own cause or suppressed
exception).
**Minor suggestion:** Consider adding a Javadoc comment explaining this
method's behavior and its relationship to `causeToString`, especially the
recursive nature.
_Claude Code on behalf of Guillaume Nodet_
##########
surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/SmartStackTraceParserTest.java:
##########
@@ -290,6 +292,30 @@ public void testStackTraceWithFocusOnClassAsString() {
}
}
+ @Test
Review Comment:
**Good test coverage for basic cases**
These tests verify the core functionality works correctly.
**Suggestion for additional test coverage:**
Consider adding tests for more complex scenarios to ensure robustness:
1. **Multiple suppressed exceptions:**
```java
RuntimeException main = new RuntimeException("main");
main.addSuppressed(new IllegalStateException("suppressed 1"));
main.addSuppressed(new IllegalArgumentException("suppressed 2"));
// Verify both appear in order
```
2. **Nested suppressed exceptions (suppressed with its own suppressed):**
```java
Exception inner = new IllegalStateException("inner suppressed");
Exception outer = new IOException("outer suppressed");
outer.addSuppressed(inner);
RuntimeException main = new RuntimeException("main");
main.addSuppressed(outer);
// Verify nested structure is preserved
```
3. **Suppressed exception with a cause chain:**
```java
Exception cause = new SQLException("db error");
Exception suppressed = new IOException("cleanup failed", cause);
RuntimeException main = new RuntimeException("main");
main.addSuppressed(suppressed);
// Verify both suppressed and its cause appear
```
These edge cases would ensure the recursive logic handles all scenarios
correctly.
_Claude Code on behalf of Guillaume Nodet_
--
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]