1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.surefire.booterclient.output;
20
21 import java.io.IOException;
22 import java.util.function.Function;
23
24 final class MultipleFailureException extends IOException {
25 void addException(Throwable exception) {
26 addSuppressed(exception);
27 }
28
29 boolean hasNestedExceptions() {
30 return getSuppressed().length != 0;
31 }
32
33 @Override
34 public String getLocalizedMessage() {
35 return toMessage(Throwable::getLocalizedMessage);
36 }
37
38 @Override
39 public String getMessage() {
40 return toMessage(Throwable::getMessage);
41 }
42
43 private String toMessage(Function<Throwable, String> msg) {
44 StringBuilder messages = new StringBuilder();
45 for (Throwable exception : getSuppressed()) {
46 if (messages.length() != 0) {
47 messages.append('\n');
48 }
49 String message = msg.apply(exception);
50 messages.append(message == null ? exception.toString() : message);
51 }
52 return messages.toString();
53 }
54 }