From 8cc9f9ddcf806322fa8cc65092ed81b8a19924bb Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Wed, 22 Nov 2017 09:37:42 +0100 Subject: [PATCH] Issue #1940 Fix NPE --- .../java/org/eclipse/jetty/cdi/servlet/EmbeddedCdiHandler.java | 3 ++- .../org/eclipse/jetty/cdi/servlet/WeldInitializationTest.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/EmbeddedCdiHandler.java b/jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/EmbeddedCdiHandler.java index 01142158b2a..5359b22c090 100644 --- a/jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/EmbeddedCdiHandler.java +++ b/jetty-cdi/cdi-servlet/src/main/java/org/eclipse/jetty/cdi/servlet/EmbeddedCdiHandler.java @@ -130,7 +130,8 @@ public class EmbeddedCdiHandler extends ServletContextHandler || (weldListener instanceof HttpSessionListener) || (weldListener instanceof HttpSessionIdListener)) { - getSessionHandler().addEventListener(weldListener); + if (getSessionHandler() != null) + getSessionHandler().addEventListener(weldListener); } } finally diff --git a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/WeldInitializationTest.java b/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/WeldInitializationTest.java index 1eff479d8ca..54fa95e3ed4 100644 --- a/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/WeldInitializationTest.java +++ b/jetty-cdi/cdi-servlet/src/test/java/org/eclipse/jetty/cdi/servlet/WeldInitializationTest.java @@ -29,6 +29,7 @@ import java.net.URI; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.log.JettyLogHandler; @@ -55,7 +56,7 @@ public class WeldInitializationTest connector.setPort(0); server.addConnector(connector); - EmbeddedCdiHandler context = new EmbeddedCdiHandler(); + EmbeddedCdiHandler context = new EmbeddedCdiHandler(ServletContextHandler.SESSIONS); File baseDir = MavenTestingUtils.getTestResourcesDir();