mirror of https://github.com/apache/maven.git
[MNG-8082] Exceptions of proxied SessionScoped components are not working correctly (#1449)
Signed-off-by: Jonas Rutishauser <jonas.rutishauser@alumni.ethz.ch>
This commit is contained in:
parent
860310b692
commit
aae74dfbee
|
@ -107,7 +107,11 @@ public class SessionScope implements Scope {
|
||||||
private <T> T createProxy(Key<T> key, Provider<T> unscoped) {
|
private <T> T createProxy(Key<T> key, Provider<T> unscoped) {
|
||||||
InvocationHandler dispatcher = (proxy, method, args) -> {
|
InvocationHandler dispatcher = (proxy, method, args) -> {
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
return method.invoke(getScopeState().scope(key, unscoped).get(), args);
|
try {
|
||||||
|
return method.invoke(getScopeState().scope(key, unscoped).get(), args);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
throw e.getCause();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
Class<T> superType = (Class<T>) key.getTypeLiteral().getRawType();
|
Class<T> superType = (Class<T>) key.getTypeLiteral().getRawType();
|
||||||
Class<?>[] interfaces = getInterfaces(superType);
|
Class<?>[] interfaces = getInterfaces(superType);
|
||||||
|
|
|
@ -74,6 +74,7 @@ public class SessionScopeProxyTest {
|
||||||
assertNotNull(bean.myBean.getSession());
|
assertNotNull(bean.myBean.getSession());
|
||||||
assertNotNull(bean.myBean.getAnotherBean());
|
assertNotNull(bean.myBean.getAnotherBean());
|
||||||
assertSame(bean.myBean.getAnotherBean().getClass(), AnotherBean.class);
|
assertSame(bean.myBean.getAnotherBean().getClass(), AnotherBean.class);
|
||||||
|
assertThrows(TestException.class, () -> bean.myBean.throwException());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Named
|
@Named
|
||||||
|
@ -102,6 +103,8 @@ public class SessionScopeProxyTest {
|
||||||
Session getSession();
|
Session getSession();
|
||||||
|
|
||||||
BeanItf2 getAnotherBean();
|
BeanItf2 getAnotherBean();
|
||||||
|
|
||||||
|
void throwException() throws TestException;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BeanItf2 {}
|
interface BeanItf2 {}
|
||||||
|
@ -127,5 +130,11 @@ public class SessionScopeProxyTest {
|
||||||
public BeanItf2 getAnotherBean() {
|
public BeanItf2 getAnotherBean() {
|
||||||
return anotherBean;
|
return anotherBean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void throwException() throws TestException {
|
||||||
|
throw new TestException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class TestException extends Exception {}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue