From 78b11c35ff8ccc5782f2cb663ccec5bd19cc35fe Mon Sep 17 00:00:00 2001 From: Spencer Gibb Date: Mon, 2 Apr 2018 12:29:22 -0400 Subject: [PATCH] GenericScope throws original checked exception, rather than UndeclaredThrowableException fixes gh-349 --- .../cloud/context/scope/GenericScope.java | 5 +++++ .../refresh/RefreshScopeIntegrationTests.java | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/GenericScope.java b/spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/GenericScope.java index 452631ff..da04d187 100644 --- a/spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/GenericScope.java +++ b/spring-cloud-context/src/main/java/org/springframework/cloud/context/scope/GenericScope.java @@ -14,6 +14,7 @@ package org.springframework.cloud.context.scope; import java.lang.reflect.Method; +import java.lang.reflect.UndeclaredThrowableException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -485,6 +486,10 @@ public class GenericScope implements Scope, BeanFactoryPostProcessor, } return invocation.proceed(); } + // see gh-349. Throw the original exception rather than the UndeclaredThrowableException + catch (UndeclaredThrowableException e) { + throw e.getUndeclaredThrowable(); + } finally { lock.unlock(); } diff --git a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeIntegrationTests.java b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeIntegrationTests.java index b39a1642..df2a2df6 100644 --- a/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeIntegrationTests.java +++ b/spring-cloud-context/src/test/java/org/springframework/cloud/context/scope/refresh/RefreshScopeIntegrationTests.java @@ -122,10 +122,19 @@ public class RefreshScopeIntegrationTests { ExampleService.event.getName()); } - public static interface Service { + // see gh-349 + @Test(expected = ServiceException.class) + @DirtiesContext + public void testCheckedException() throws Exception { + this.service.throwsException(); + } + + public interface Service { String getMessage(); + String throwsException() throws ServiceException; + } public static class ExampleService implements Service, InitializingBean, @@ -189,12 +198,19 @@ public class RefreshScopeIntegrationTests { return this.message; } + @Override + public String throwsException() throws ServiceException { + throw new ServiceException(); + } + @Override public void onApplicationEvent(RefreshScopeRefreshedEvent e) { event = e; } } + public static class ServiceException extends Exception {} + @Configuration @EnableConfigurationProperties(TestProperties.class) @EnableAutoConfiguration