Skip to content

Commit f3e2454

Browse files
committed
ISSUE #17874 Make use of Java 17 pattern matching switch statements
1 parent 0c61205 commit f3e2454

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

libs/core/src/main/java/org/opensearch/ExceptionsHelper.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,14 @@ public static RestStatus status(Throwable t) {
105105
}
106106

107107
public static String summaryMessage(Throwable t) {
108-
if (t != null) {
109-
if (t instanceof OpenSearchException) {
110-
return getExceptionSimpleClassName(t) + "[" + t.getMessage() + "]";
111-
} else if (t instanceof IllegalArgumentException) {
112-
return "Invalid argument";
113-
} else if (t instanceof JsonParseException) {
114-
return "Failed to parse JSON";
115-
} else if (t instanceof OpenSearchRejectedExecutionException) {
116-
return "Too many requests";
117-
}
118-
}
119-
return "Internal failure";
108+
return switch (t) {
109+
case OpenSearchException ose -> getExceptionSimpleClassName(t) + "[" + t.getMessage() + "]";
110+
case IllegalArgumentException iae -> "Invalid argument";
111+
case JsonParseException jpe -> "Failed to parse JSON";
112+
case OpenSearchRejectedExecutionException osre -> "Too many requests";
113+
case null -> "Internal failure";
114+
default -> "Internal failure";
115+
};
120116
}
121117

122118
public static Throwable unwrapCause(Throwable t) {

0 commit comments

Comments
 (0)