Skip to content

Commit e219576

Browse files
committed
Defensive catching of any Throwable subclasses instead of just Error
Issue: SPR-14329 Issue: SPR-14323 (cherry picked from commit a9fda3e)
1 parent 2fd691b commit e219576

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

spring-messaging/src/main/java/org/springframework/messaging/support/AbstractMessageChannel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -126,9 +126,9 @@ public final boolean send(Message<?> message, long timeout) {
126126
}
127127
throw new MessageDeliveryException(message,"Failed to send message to " + this, ex);
128128
}
129-
catch (Error ex) {
129+
catch (Throwable err) {
130130
MessageDeliveryException ex2 =
131-
new MessageDeliveryException(message, "Failed to send message to " + this, ex);
131+
new MessageDeliveryException(message, "Failed to send message to " + this, err);
132132
chain.triggerAfterSendCompletion(message, this, sent, ex2);
133133
throw ex2;
134134
}

spring-messaging/src/main/java/org/springframework/messaging/support/ExecutorSubscribableChannel.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -99,7 +99,7 @@ public boolean sendInternal(Message<?> message, long timeout) {
9999

100100

101101
/**
102-
* Invoke a MessageHandler with ExecutorChannelInterceptor's.
102+
* Invoke a MessageHandler with ExecutorChannelInterceptors.
103103
*/
104104
private class SendTask implements MessageHandlingRunnable {
105105

@@ -143,10 +143,11 @@ public void run() {
143143
String description = "Failed to handle " + message + " to " + this + " in " + this.messageHandler;
144144
throw new MessageDeliveryException(message, description, ex);
145145
}
146-
catch (Error ex) {
146+
catch (Throwable err) {
147147
String description = "Failed to handle " + message + " to " + this + " in " + this.messageHandler;
148-
triggerAfterMessageHandled(message, new MessageDeliveryException(message, description, ex));
149-
throw ex;
148+
MessageDeliveryException ex2 = new MessageDeliveryException(message, description, err);
149+
triggerAfterMessageHandled(message, ex2);
150+
throw ex2;
150151
}
151152
}
152153

spring-tx/src/main/java/org/springframework/transaction/support/TransactionTemplate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -142,7 +142,7 @@ public <T> T execute(TransactionCallback<T> action) throws TransactionException
142142
rollbackOnException(status, err);
143143
throw err;
144144
}
145-
catch (Exception ex) {
145+
catch (Throwable ex) {
146146
// Transactional code threw unexpected exception -> rollback
147147
rollbackOnException(status, ex);
148148
throw new UndeclaredThrowableException(ex, "TransactionCallback threw undeclared checked exception");

spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/DispatcherPortlet.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -687,7 +687,7 @@ protected void doActionService(ActionRequest request, ActionResponse response) t
687687
throw ex;
688688
}
689689
}
690-
catch (Error err) {
690+
catch (Throwable err) {
691691
PortletException ex =
692692
new PortletException("Error occured during request processing: " + err.getMessage(), err);
693693
// Trigger after-completion for thrown exception.
@@ -800,7 +800,7 @@ protected void doRenderService(RenderRequest request, RenderResponse response) t
800800
triggerAfterRenderCompletion(mappedHandler, interceptorIndex, request, response, ex);
801801
throw ex;
802802
}
803-
catch (Error err) {
803+
catch (Throwable err) {
804804
PortletException ex =
805805
new PortletException("Error occured during request processing: " + err.getMessage(), err);
806806
// Trigger after-completion for thrown exception.
@@ -891,7 +891,7 @@ protected void doResourceService(ResourceRequest request, ResourceResponse respo
891891
triggerAfterResourceCompletion(mappedHandler, interceptorIndex, request, response, ex);
892892
throw ex;
893893
}
894-
catch (Error err) {
894+
catch (Throwable err) {
895895
PortletException ex =
896896
new PortletException("Error occured during request processing: " + err.getMessage(), err);
897897
// Trigger after-completion for thrown exception.
@@ -965,7 +965,7 @@ protected void doEventService(EventRequest request, EventResponse response) thro
965965
throw ex;
966966
}
967967
}
968-
catch (Error err) {
968+
catch (Throwable err) {
969969
PortletException ex =
970970
new PortletException("Error occured during request processing: " + err.getMessage(), err);
971971
// Trigger after-completion for thrown exception.

spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ protected void doDispatch(HttpServletRequest request, HttpServletResponse respon
975975
catch (Exception ex) {
976976
triggerAfterCompletion(processedRequest, response, mappedHandler, ex);
977977
}
978-
catch (Error err) {
978+
catch (Throwable err) {
979979
triggerAfterCompletionWithError(processedRequest, response, mappedHandler, err);
980980
}
981981
finally {
@@ -1300,7 +1300,7 @@ private void triggerAfterCompletion(HttpServletRequest request, HttpServletRespo
13001300
}
13011301

13021302
private void triggerAfterCompletionWithError(HttpServletRequest request, HttpServletResponse response,
1303-
HandlerExecutionChain mappedHandler, Error error) throws Exception {
1303+
HandlerExecutionChain mappedHandler, Throwable error) throws Exception {
13041304

13051305
ServletException ex = new NestedServletException("Handler processing failed", error);
13061306
if (mappedHandler != null) {

0 commit comments

Comments
 (0)