dcapwell commented on code in PR #2104:
URL: https://github.com/apache/cassandra/pull/2104#discussion_r1134561570
##########
src/java/org/apache/cassandra/streaming/StreamSession.java:
##########
@@ -1342,37 +1342,37 @@ public static StringBuilder boundStackTrace(Throwable
e, int limit)
{
Set<Throwable> visited = Collections.newSetFromMap(new
IdentityHashMap<>());
StringBuilder out = new StringBuilder();
- return boundStackTrace(e, limit, visited, out);
+ int counter = limit;
+ return boundStackTrace(e, limit, counter, visited, out);
}
- public static StringBuilder boundStackTrace(Throwable e, int limit,
Set<Throwable> visited, StringBuilder out)
+ public static StringBuilder boundStackTrace(Throwable e, int limit, int
counter, Set<Throwable> visited, StringBuilder out)
{
if (e == null)
- return null;
+ return out;
if (!visited.add(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)
- {
- out.append(e.getClass().getName()).append(":
").append(e.getMessage()).append('\n');
- boundStackTrace(e.getCause(), limit, visited, out);
- return out;
- }
+ int stackTraceSize = e.getStackTrace().length;
StackTraceElement[] stackTrace = e.getStackTrace();
- StringBuilder stackTraceBuilder = new StringBuilder();
- stackTraceBuilder.append(e.getClass().getName() + ": " +
e.getMessage()).append('\n');
+ out.append(e.getClass().getName() + ": " +
e.getMessage()).append('\n');
- for (int i = 0; i < limit; i++)
+ int i = 0;
+ while (i < Math.min(stackTraceSize, limit) && counter > 0)
{
- stackTraceBuilder.append('\t').append(stackTrace[i]);
- if (e.getCause() == null && i == limit - 1) continue;
- stackTraceBuilder.append('\n');
+ out.append('\t').append(stackTrace[i]);
+ if (e.getCause() == null && i == limit - 1) break;
Review Comment:
if this is to avoid the last `\n` you can do the following in the top-level
method
```
out.setLength(out.length() - 1);
```
--
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]