Fix JSP tag release · apache/tomcat@be8e321 · GitHub
Skip to content

Commit

Permalink
Fix JSP tag release
Browse files Browse the repository at this point in the history
BZ 69399: Fix regression caused by the improvement 69333 which caused
the tag release() to be called  when using tag pooling, and to be
skipped when not using it.
Patch submitted by Michal Sobkiewicz.
  • Loading branch information
rmaucher committed Oct 15, 2024
1 parent c34acb7 commit be8e321
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion java/org/apache/jasper/compiler/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -2371,7 +2371,7 @@ private void generateCustomEnd(Node.CustomTag n, String tagHandlerVar,
out.print(".reuse(");
out.print(tagHandlerVar);
out.println(");");

} else {
// Clean-up
out.printin("org.apache.jasper.runtime.JspRuntimeLibrary.releaseTag(");
out.print(tagHandlerVar);
Expand Down
51 changes: 51 additions & 0 deletions test/org/apache/jasper/compiler/TestGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,25 @@ public void setData(String data) {
}
}

private static boolean tagTesterTagReleaseReleased = false;

public static class TesterTagRelease extends TesterTag {
private String data;

public String getData() {
return data;
}

public void setData(String data) {
this.data = data;
}

@Override
public void release() {
tagTesterTagReleaseReleased = true;
}
}

public static class DataPropertyEditor extends PropertyEditorSupport {
}

Expand Down Expand Up @@ -967,6 +986,38 @@ public void testBug65390() throws Exception {
Assert.assertEquals(body.toString(), HttpServletResponse.SC_OK, rc);
}

@Test
public void testTagReleaseWithPooling() throws Exception {
doTestTagRelease(true);
}

@Test
public void testTagReleaseWithoutPooling() throws Exception {
doTestTagRelease(false);
}

public void doTestTagRelease(boolean enablePooling) throws Exception {
tagTesterTagReleaseReleased = false;
Tomcat tomcat = getTomcatInstance();

File appDir = new File("test/webapp");
Context ctxt = tomcat.addContext("", appDir.getAbsolutePath());
ctxt.addServletContainerInitializer(new JasperInitializer(), null);

Tomcat.initWebappDefaults(ctxt);
Wrapper w = (Wrapper) ctxt.findChild("jsp");
w.addInitParameter("enablePooling", String.valueOf(enablePooling));

tomcat.start();

getUrl("http://localhost:" + getPort() + "/jsp/generator/release.jsp");
if (enablePooling) {
Assert.assertFalse(tagTesterTagReleaseReleased);
} else {
Assert.assertTrue(tagTesterTagReleaseReleased);
}
}

private void doTestJsp(String jspName) throws Exception {
doTestJsp(jspName, HttpServletResponse.SC_OK);
}
Expand Down
5 changes: 5 additions & 0 deletions test/webapp/WEB-INF/bugs.tld
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@
<tag-class>org.apache.jasper.compiler.TestGenerator$TesterTagA</tag-class>
<body-content>JSP</body-content>
</tag>
<tag>
<name>TesterTagRelease</name>
<tag-class>org.apache.jasper.compiler.TestGenerator$TesterTagRelease</tag-class>
<body-content>JSP</body-content>
</tag>
<tag>
<name>TesterScriptingTag</name>
<tag-class>org.apache.jasper.compiler.TestGenerator$TesterScriptingTag</tag-class>
Expand Down
18 changes: 18 additions & 0 deletions test/webapp/jsp/generator/release.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<%--
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.
--%>
<%@ taglib uri="http://tomcat.apache.org/bugs" prefix="bugs" %>
<bugs:TesterTagRelease/>
10 changes: 10 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@
</fix>
</changelog>
</subsection>
<subsection name="Jasper">
<changelog>
<fix>
<bug>69399</bug>: Fix regression caused by the improvement
<bug>69333</bug> which caused the tag <code>release</code> to be called
when using tag pooling, and to be skipped when not using it.
Patch submitted by Michal Sobkiewicz. (remm)
</fix>
</changelog>
</subsection>
<subsection name="Other">
<changelog>
<update>
Expand Down

0 comments on commit be8e321

Please sign in to comment.