This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.0.x by this push: new a3e57c608b 66031: Fix NPE when using a custom JspFactory a3e57c608b is described below commit a3e57c608bffe150377a753b64603c8b066016e8 Author: remm <r...@apache.org> AuthorDate: Mon Apr 25 18:01:36 2022 +0200 66031: Fix NPE when using a custom JspFactory Patch by Jean-Louis Monteiro. --- .../apache/jasper/servlet/JasperInitializer.java | 7 ++- .../jasper/servlet/TestJasperInitializer.java | 71 ++++++++++++++++++++++ webapps/docs/changelog.xml | 8 +++ 3 files changed, 83 insertions(+), 3 deletions(-) diff --git a/java/org/apache/jasper/servlet/JasperInitializer.java b/java/org/apache/jasper/servlet/JasperInitializer.java index f2f3700e67..c23d74e5ee 100644 --- a/java/org/apache/jasper/servlet/JasperInitializer.java +++ b/java/org/apache/jasper/servlet/JasperInitializer.java @@ -43,7 +43,6 @@ public class JasperInitializer implements ServletContainerInitializer { private static final String MSG = "org.apache.jasper.servlet.JasperInitializer"; private final Log log = LogFactory.getLog(JasperInitializer.class); // must not be static - private static JspFactoryImpl defaultFactory; /** * Preload classes required at runtime by a JSP servlet so that * we don't get a defineClassInPackage security exception. @@ -53,7 +52,6 @@ public class JasperInitializer implements ServletContainerInitializer { SecurityClassLoad.securityClassLoad(factory.getClass().getClassLoader()); if (JspFactory.getDefaultFactory() == null) { JspFactory.setDefaultFactory(factory); - defaultFactory = factory; } } @@ -105,7 +103,10 @@ public class JasperInitializer implements ServletContainerInitializer { throw new ServletException(e); } } - defaultFactory.setPoolSize(poolSize); + JspFactory factory = JspFactory.getDefaultFactory(); + if (factory instanceof JspFactoryImpl) { + ((JspFactoryImpl) factory).setPoolSize(poolSize); + } } diff --git a/test/org/apache/jasper/servlet/TestJasperInitializer.java b/test/org/apache/jasper/servlet/TestJasperInitializer.java new file mode 100644 index 0000000000..4b30aaaef8 --- /dev/null +++ b/test/org/apache/jasper/servlet/TestJasperInitializer.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.jasper.servlet; + +import java.util.Collections; +import java.util.concurrent.atomic.AtomicInteger; + +import jakarta.servlet.descriptor.JspConfigDescriptor; +import jakarta.servlet.jsp.JspFactory; + +import org.junit.Assert; +import org.junit.Test; + +import org.apache.jasper.Constants; +import org.apache.jasper.runtime.JspFactoryImpl; +import org.apache.tomcat.unittest.TesterServletContext; + +public class TestJasperInitializer { + + @Test + public void testPoolSize() throws Exception { + + final AtomicInteger actualPoolSize = new AtomicInteger(-1); + final JspFactoryImpl defaultFactory = new JspFactoryImpl() { + @Override + public void setPoolSize(int poolSize) { + actualPoolSize.set(poolSize); + super.setPoolSize(poolSize); + } + }; + + JspFactory.setDefaultFactory(defaultFactory); + new JasperInitializer().onStartup(Collections.emptySet(), new TesterServletContext(){ + @Override + public void setAttribute(String name, Object object) { + // ignore + } + + @Override + public JspConfigDescriptor getJspConfigDescriptor() { + return null; + } + + @Override + public String getInitParameter(String name) { + if (Constants.JSP_FACTORY_POOL_SIZE_INIT_PARAM.equals(name)) { + return "3"; + } + return super.getInitParameter(name); + } + }); + + // Default value is 8 in JasperInitializer but we have overridden it + Assert.assertEquals(3, actualPoolSize.get()); + } + +} diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index cc1849addf..9d9790269c 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -139,6 +139,14 @@ </fix> </changelog> </subsection> + <subsection name="Jasper"> + <changelog> + <fix> + <bug>66031</bug>: Fix NPE when using a custom JspFactory. Patch by + Jean-Louis Monteiro. (remm) + </fix> + </changelog> + </subsection> </section> <section name="Tomcat 10.0.20 (markt)" rtext="2022-04-01"> <subsection name="Catalina"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org