Skip to content

Commit a784eb0

Browse files
quaffrstoyanchev
authored andcommitted
Improve DisconnectedClientHelper to better guard ClassNotFoundException
Before this commit, WebClientException is ignored if RestClientException is not present. Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
1 parent fa40406 commit a784eb0

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

spring-web/src/main/java/org/springframework/web/util/DisconnectedClientHelper.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* error stacktrace at TRACE level.
3737
*
3838
* @author Rossen Stoyanchev
39+
* @author Yanming Zhou
3940
* @since 6.1
4041
*/
4142
public class DisconnectedClientHelper {
@@ -50,16 +51,8 @@ public class DisconnectedClientHelper {
5051
private static final Set<Class<?>> CLIENT_EXCEPTION_TYPES = new HashSet<>(2);
5152

5253
static {
53-
try {
54-
ClassLoader classLoader = DisconnectedClientHelper.class.getClassLoader();
55-
CLIENT_EXCEPTION_TYPES.add(ClassUtils.forName(
56-
"org.springframework.web.client.RestClientException", classLoader));
57-
CLIENT_EXCEPTION_TYPES.add(ClassUtils.forName(
58-
"org.springframework.web.reactive.function.client.WebClientException", classLoader));
59-
}
60-
catch (ClassNotFoundException ex) {
61-
// ignore
62-
}
54+
registerClientExceptionType("org.springframework.web.client.RestClientException");
55+
registerClientExceptionType("org.springframework.web.reactive.function.client.WebClientException");
6356
}
6457

6558

@@ -135,4 +128,14 @@ public static boolean isClientDisconnectedException(@Nullable Throwable ex) {
135128
return false;
136129
}
137130

131+
private static void registerClientExceptionType(String type) {
132+
try {
133+
ClassLoader classLoader = DisconnectedClientHelper.class.getClassLoader();
134+
CLIENT_EXCEPTION_TYPES.add(ClassUtils.forName(type, classLoader));
135+
}
136+
catch (ClassNotFoundException ex) {
137+
// ignore
138+
}
139+
}
140+
138141
}

0 commit comments

Comments
 (0)