From aa97d4f64a9709492c1e30853ce9a977d0387ce1 Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Tue, 17 Oct 2023 17:02:10 +0200 Subject: [PATCH] WELD-2762 Do not swallow exceptions occuring during HTTP session creation --- impl/src/main/java/org/jboss/weld/injection/Exceptions.java | 2 +- .../java/org/jboss/weld/security/NewInstanceAction.java | 5 +++-- .../web/context/beanstore/http/LazySessionBeanStore.java | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/impl/src/main/java/org/jboss/weld/injection/Exceptions.java b/impl/src/main/java/org/jboss/weld/injection/Exceptions.java index dc7f6562f2b..8670d6b6ba8 100644 --- a/impl/src/main/java/org/jboss/weld/injection/Exceptions.java +++ b/impl/src/main/java/org/jboss/weld/injection/Exceptions.java @@ -89,5 +89,5 @@ public static void rethrowException(NoSuchMethodException e, Class extends AbstractGenericReflectionAction implements PrivilegedExceptionAction { @@ -29,7 +30,7 @@ public NewInstanceAction(Class javaClass) { } @Override - public T run() throws InstantiationException, IllegalAccessException { - return javaClass.newInstance(); + public T run() throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { + return javaClass.getDeclaredConstructor().newInstance(); } } diff --git a/modules/web/src/main/java/org/jboss/weld/module/web/context/beanstore/http/LazySessionBeanStore.java b/modules/web/src/main/java/org/jboss/weld/module/web/context/beanstore/http/LazySessionBeanStore.java index 13ac3e3950e..438b41d7d48 100644 --- a/modules/web/src/main/java/org/jboss/weld/module/web/context/beanstore/http/LazySessionBeanStore.java +++ b/modules/web/src/main/java/org/jboss/weld/module/web/context/beanstore/http/LazySessionBeanStore.java @@ -85,10 +85,10 @@ protected HttpSession getSession(boolean create) { try { return SessionHolder.getSession(request, create); } catch (IllegalStateException e) { - // If container can't create an underlying session, invalidate the - // current one + // If container can't create an underlying session, invalidate the current one detach(); - return null; + // re-throw the exception to properly show cause and message + throw e; } }