From ff4f2ef28f4f83036f5c409116ab457dfd7f5348 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Thu, 21 Jan 2021 15:27:15 +1100 Subject: [PATCH] only allow adding ServletContainerInitializers before starting Signed-off-by: Lachlan Roberts --- .../org/eclipse/jetty/servlet/ServletContextHandler.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java index f7b18da4018..d2012a901e4 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java @@ -703,6 +703,9 @@ public class ServletContextHandler extends ContextHandler */ public void addServletContainerInitializer(ServletContainerInitializer containerInitializer) { + if (!isStopped()) + throw new IllegalStateException("ServletContainerInitializers should be added before starting"); + addServletContainerInitializer(containerInitializer, Collections.emptySet()); } @@ -714,6 +717,9 @@ public class ServletContextHandler extends ContextHandler */ public void addServletContainerInitializer(ServletContainerInitializer containerInitializer, Set> classes) { + if (!isStopped()) + throw new IllegalStateException("ServletContainerInitializers should be added before starting"); + addManaged(new Initializer(this, containerInitializer, classes)); }