Skip to content

Commit

Permalink
[MNG-8082] Exceptions of proxied SessionScoped components are not wor…
Browse files Browse the repository at this point in the history
…king correctly (apache#1449)

Signed-off-by: Jonas Rutishauser <[email protected]>
  • Loading branch information
jonasrutishauser authored Apr 23, 2024
1 parent 860310b commit aae74df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 107,11 @@ public <T> Provider<T> scope(final Key<T> key, final Provider<T> unscoped) {
private <T> T createProxy(Key<T> key, Provider<T> unscoped) {
InvocationHandler dispatcher = (proxy, method, args) -> {
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<?>[] interfaces = getInterfaces(superType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 74,7 @@ void testProxiedSessionScopedBean() throws ComponentLookupException {
assertNotNull(bean.myBean.getSession());
assertNotNull(bean.myBean.getAnotherBean());
assertSame(bean.myBean.getAnotherBean().getClass(), AnotherBean.class);
assertThrows(TestException.class, () -> bean.myBean.throwException());
}

@Named
Expand Down Expand Up @@ -102,6 103,8 @@ interface BeanItf {
Session getSession();

BeanItf2 getAnotherBean();

void throwException() throws TestException;
}

interface BeanItf2 {}
Expand All @@ -127,5 130,11 @@ public Session getSession() {
public BeanItf2 getAnotherBean() {
return anotherBean;
}

public void throwException() throws TestException {
throw new TestException();
}
}

static class TestException extends Exception {}
}

0 comments on commit aae74df

Please sign in to comment.