@@ -40,13 +40,15 @@ String render() {
4040 }
4141
4242 private void appendStackTrace () {
43- if (appendLine (throwable .toString ())) {
43+ builder .append (throwable ).append (System .lineSeparator ());
44+ if (isOverLimit ()) {
4445 return ;
4546 }
4647
4748 StackTraceElement [] stackTraceElements = throwable .getStackTrace ();
4849 for (StackTraceElement stackTraceElement : stackTraceElements ) {
49- if (appendLine ("\t at " + stackTraceElement )) {
50+ builder .append ("\t at " ).append (stackTraceElement ).append (System .lineSeparator ());
51+ if (isOverLimit ()) {
5052 return ;
5153 }
5254 }
@@ -75,7 +77,13 @@ private boolean appendInnerStacktrace(
7577 String caption ,
7678 Set <Throwable > seen ) {
7779 if (seen .contains (innerThrowable )) {
78- appendLine (prefix + caption + "[CIRCULAR REFERENCE: " + innerThrowable + "]" );
80+ builder
81+ .append (prefix )
82+ .append (caption )
83+ .append ("[CIRCULAR REFERENCE: " )
84+ .append (innerThrowable )
85+ .append ("]" )
86+ .append (System .lineSeparator ());
7987 return true ;
8088 }
8189 seen .add (innerThrowable );
@@ -96,20 +104,32 @@ private boolean appendInnerStacktrace(
96104 lastSharedFrameIndex --;
97105 }
98106
99- if (appendLine (prefix + caption + innerThrowable )) {
107+ builder .append (prefix ).append (caption ).append (innerThrowable ).append (System .lineSeparator ());
108+ if (isOverLimit ()) {
100109 return true ;
101110 }
102111
103112 for (int i = 0 ; i <= lastSharedFrameIndex ; i ++) {
104113 StackTraceElement stackTraceElement = currentElements [i ];
105- if (appendLine (prefix + "\t at " + stackTraceElement )) {
114+ builder
115+ .append (prefix )
116+ .append ("\t at " )
117+ .append (stackTraceElement )
118+ .append (System .lineSeparator ());
119+ if (isOverLimit ()) {
106120 return true ;
107121 }
108122 }
109123
110124 int duplicateFrames = currentElements .length - 1 - lastSharedFrameIndex ;
111125 if (duplicateFrames != 0 ) {
112- if (appendLine (prefix + "\t ... " + duplicateFrames + " more" )) {
126+ builder
127+ .append (prefix )
128+ .append ("\t ... " )
129+ .append (duplicateFrames )
130+ .append (" more" )
131+ .append (System .lineSeparator ());
132+ if (isOverLimit ()) {
113133 return true ;
114134 }
115135 }
@@ -128,12 +148,7 @@ private boolean appendInnerStacktrace(
128148 return false ;
129149 }
130150
131- /**
132- * Append the string as a new line on {@link #builder}, returning {@code true} if the builder now
133- * exceeds the length limit.
134- */
135- private boolean appendLine (String s ) {
136- builder .append (s ).append (System .lineSeparator ());
151+ private boolean isOverLimit () {
137152 return builder .length () >= lengthLimit ;
138153 }
139154}
0 commit comments