From 28381eab2191c2492d8ebc73bb7fd3e17f08b52b 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 | 1 - .../java/org/jboss/weld/security/NewInstanceAction.java | 5 +++-- .../web/context/beanstore/http/LazySessionBeanStore.java | 6 +++--- 3 files changed, 6 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..39a8e04bdab 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,4 @@ 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; } }