NateAdere commented on code in PR #2104:
URL: https://github.com/apache/cassandra/pull/2104#discussion_r1132732761
##########
src/java/org/apache/cassandra/streaming/StreamSession.java:
##########
@@ -1340,32 +1338,41 @@ public String toString()
'}';
}
- public static Throwable boundStackTrace(Throwable e, int limit)
+ public static StringBuilder boundStackTrace(Throwable e, int limit)
{
Set<Throwable> visited = Collections.newSetFromMap(new
IdentityHashMap<>());
- return boundStackTrace(e, limit, visited);
+ StringBuilder out = new StringBuilder();
+ return boundStackTrace(e, limit, visited, out);
}
- public static Throwable boundStackTrace(Throwable e, int limit,
Set<Throwable> visited)
+ public static StringBuilder boundStackTrace(Throwable e, int limit,
Set<Throwable> visited, StringBuilder out)
{
if (e == null)
- return e;
+ return null;
if (!visited.add(e))
- return e;
+ return out.append("[CIRCULAR REFERENCE:
").append(e.getClass().getName()).append(":
").append(e.getMessage()).append("]");
visited.add(e);
if (e.getStackTrace().length == 0 || e.getStackTrace().length < limit)
{
- boundStackTrace(e.getCause(), limit, visited);
- return e;
+ out.append(e.getClass().getName()).append(":
").append(e.getMessage()).append('\n');
+ boundStackTrace(e.getCause(), limit, visited, out);
+ return out;
}
StackTraceElement[] stackTrace = e.getStackTrace();
- StackTraceElement[] limitedStackTrace = Arrays.copyOfRange(stackTrace,
0, limit);
- e.setStackTrace(limitedStackTrace);
- boundStackTrace(e.getCause(), limit, visited);
+ StringBuilder stackTraceBuilder = new StringBuilder();
+ stackTraceBuilder.append(e.getClass().getName() + ": " +
e.getMessage()).append('\n');
+
+ for (int i = 0; i < limit; i++)
+ {
+ stackTraceBuilder.append('\t').append(stackTrace[i]);
+ if (e.getCause() == null && i == limit - 1) continue;
Review Comment:
This was added to avoid an extra new line that is added to the last
exception when creating a bounded stringbuilder for a nested exception
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]