This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/master by this push: new aae74dfbee [MNG-8082] Exceptions of proxied SessionScoped components are not working correctly (#1449) aae74dfbee is described below commit aae74dfbeefbb2f0a515449a8873f4be67e20b2f Author: Jonas Rutishauser <jonas.rutishau...@alumni.ethz.ch> AuthorDate: Tue Apr 23 14:52:20 2024 +0200 [MNG-8082] Exceptions of proxied SessionScoped components are not working correctly (#1449) Signed-off-by: Jonas Rutishauser <jonas.rutishau...@alumni.ethz.ch> --- .../org/apache/maven/session/scope/internal/SessionScope.java | 6 +++++- .../org/apache/maven/session/scope/SessionScopeProxyTest.java | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/maven-core/src/main/java/org/apache/maven/session/scope/internal/SessionScope.java b/maven-core/src/main/java/org/apache/maven/session/scope/internal/SessionScope.java index a29b16fb2d..ef60843d9d 100644 --- a/maven-core/src/main/java/org/apache/maven/session/scope/internal/SessionScope.java +++ b/maven-core/src/main/java/org/apache/maven/session/scope/internal/SessionScope.java @@ -107,7 +107,11 @@ public class SessionScope implements Scope { 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); diff --git a/maven-core/src/test/java/org/apache/maven/session/scope/SessionScopeProxyTest.java b/maven-core/src/test/java/org/apache/maven/session/scope/SessionScopeProxyTest.java index 5988c64c9e..00bc450b14 100644 --- a/maven-core/src/test/java/org/apache/maven/session/scope/SessionScopeProxyTest.java +++ b/maven-core/src/test/java/org/apache/maven/session/scope/SessionScopeProxyTest.java @@ -74,6 +74,7 @@ public class SessionScopeProxyTest { assertNotNull(bean.myBean.getSession()); assertNotNull(bean.myBean.getAnotherBean()); assertSame(bean.myBean.getAnotherBean().getClass(), AnotherBean.class); + assertThrows(TestException.class, () -> bean.myBean.throwException()); } @Named @@ -102,6 +103,8 @@ public class SessionScopeProxyTest { Session getSession(); BeanItf2 getAnotherBean(); + + void throwException() throws TestException; } interface BeanItf2 {} @@ -127,5 +130,11 @@ public class SessionScopeProxyTest { public BeanItf2 getAnotherBean() { return anotherBean; } + + public void throwException() throws TestException { + throw new TestException(); + } } + + static class TestException extends Exception {} }