Skip to content

Commit 7d45369

Browse files
committed
Simplify MultitargetException error dumping code
1 parent 8debc4a commit 7d45369

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

src/main/java/net/tascalate/concurrent/MultitargetException.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public static MultitargetException of(final Throwable exception) {
7474

7575
@Override
7676
public String toString() {
77+
// Exclude getMessage / getLocalizedMessage to avoid infinite recursion
7778
return getClass().getName();
7879
}
7980

@@ -86,15 +87,11 @@ public String getMessage() {
8687

8788
void printDetails(PrintWriter w, Set<Throwable> visited) {
8889
visited.add(this);
89-
w.println(toStringSafe());
90+
w.println(this);
9091
printExceptions(w, (ex, padding) -> {
9192
PrintWriter pw = new PrintWriter(new PaddedWriter(w, padding), true);
9293
if (visited.contains(ex)) {
93-
String message = ex instanceof MultitargetException ?
94-
((MultitargetException)ex).toStringSafe()
95-
:
96-
ex.toString();
97-
pw.println("\t[CIRCULAR REFERENCE:" + message + "]");
94+
pw.println("\t[CIRCULAR REFERENCE:" + ex + "]");
9895
} else {
9996
if (ex instanceof MultitargetException) {
10097
((MultitargetException)ex).printDetails(pw, visited);
@@ -121,18 +118,14 @@ void printExceptions(PrintStream s, Set<Throwable> visited) {
121118

122119
//super.printStackTrace(s);
123120
// Print our stack trace
124-
s.println(toStringSafe());
121+
s.println(this);
125122
for (StackTraceElement trace : getStackTrace())
126123
s.println("\tat " + trace);
127124

128125
printExceptions(s, (ex, padding) -> {
129126
PrintStream ps = new PrintStream(new PaddedOutputStream(s, padding));
130127
if (visited.contains(ex)) {
131-
String message = ex instanceof MultitargetException ?
132-
((MultitargetException)ex).toStringSafe()
133-
:
134-
ex.toString();
135-
ps.println("\t[CIRCULAR REFERENCE:" + message + "]");
128+
ps.println("\t[CIRCULAR REFERENCE:" + ex + "]");
136129
} else {
137130
if (ex instanceof MultitargetException) {
138131
((MultitargetException)ex).printExceptions(ps, visited);
@@ -154,18 +147,14 @@ void printExceptions(PrintWriter w, Set<Throwable> visited) {
154147

155148
//super.printStackTrace(s);
156149
// Print our stack trace
157-
w.println(toStringSafe());
150+
w.println(this);
158151
for (StackTraceElement trace : getStackTrace())
159152
w.println("\tat " + trace);
160153

161154
printExceptions(w, (ex, padding) -> {
162155
PrintWriter pw = new PrintWriter(new PaddedWriter(w, padding), true);
163156
if (visited.contains(ex)) {
164-
String message = ex instanceof MultitargetException ?
165-
((MultitargetException)ex).toStringSafe()
166-
:
167-
ex.toString();
168-
pw.println("\t[CIRCULAR REFERENCE:" + message + "]");
157+
pw.println("\t[CIRCULAR REFERENCE:" + ex + "]");
169158
} else {
170159
if (ex instanceof MultitargetException) {
171160
((MultitargetException)ex).printExceptions(pw, visited);
@@ -207,10 +196,6 @@ private static <O extends Appendable> void printException(String idx, Throwable
207196
}
208197
}
209198

210-
String toStringSafe() {
211-
return getClass().getName();
212-
}
213-
214199
private static <T> Set<T> newDejavueSet() {
215200
return Collections.newSetFromMap(new IdentityHashMap<T, Boolean>());
216201
}

0 commit comments

Comments
 (0)