From 72b44cebea31e9db6faffa5c3e62b8f0d560e19b Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 21 Nov 2022 17:36:25 +0100 Subject: [PATCH] Catch Error for SourceHttpMessageConverter in WebMvcConfigurationSupport Prior to this commit, the addDefaultHttpMessageConverters() method in WebMvcConfigurationSupport caught Throwable for SourceHttpMessageConverter instantiation; whereas, the rest of the code base correctly catches Error for SourceHttpMessageConverter instantiation (to handle errors such as NoClassDefFoundError). Throwable should not be caught since it can mask other categories of failures (such as configuration errors). This commit therefore switches to catching Error for SourceHttpMessageConverter instantiation in WebMvcConfigurationSupport. Closes gh-29537 --- .../config/annotation/WebMvcConfigurationSupport.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java index 262e9d9a303..18c44d61511 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -907,8 +907,8 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv try { messageConverters.add(new SourceHttpMessageConverter<>()); } - catch (Throwable ex) { - // Ignore when no TransformerFactory implementation is available... + catch (Error err) { + // Ignore when no TransformerFactory implementation is available } } messageConverters.add(new AllEncompassingFormHttpMessageConverter());