GenericScope throws original checked exception, rather than UndeclaredThrowableException
fixes gh-349
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user