truncate stack overflow error traces so the resulting messages aren't too long to post

This commit is contained in:
myk
2013-03-10 21:39:26 +00:00
parent 187f700c2c
commit c568a7cae2

View File

@@ -65,6 +65,8 @@ import forge.properties.NewConstants;
* @version V1.0 02.08.2009
*/
public class BugReporter {
private static final int _STACK_OVERFLOW_MAX_MESSAGE_LEN = 16 * 1024;
/**
* Shows exception information in a format ready to post to the forum as a crash report. Uses the exception's message
* as the reason if message is null.
@@ -90,7 +92,17 @@ public class BugReporter {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
ex.printStackTrace(pw);
sb.append(sw.toString());
String swStr = sw.toString();
if (ex instanceof StackOverflowError &&
_STACK_OVERFLOW_MAX_MESSAGE_LEN <= swStr.length()) {
// most likely a cycle. only take first portion so the message
// doesn't grow too large to post
sb.append(swStr, 0, _STACK_OVERFLOW_MAX_MESSAGE_LEN);
sb.append("\n... (truncated)");
} else {
sb.append(swStr);
}
_buildSpoilerFooter(sb);