This is an automated email from the ASF dual-hosted git repository. markt-asf pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit cecd265cc575dc1168d019b43d2c108ba8a752d7 Author: Mark Thomas <[email protected]> AuthorDate: Thu Sep 17 22:14:27 2026 +0100 Fix the tag plugin for the JSTL <c:redirtect> tag Page processing should end with the redirect --- java/org/apache/jasper/compiler/Generator.java | 31 +++++++++++++++------- java/org/apache/jasper/compiler/Node.java | 21 +++++++++++++++ .../apache/jasper/compiler/TagPluginManager.java | 6 ++++- .../compiler/tagplugin/TagPluginContext.java | 7 +++++ .../jasper/tagplugins/jstl/core/Redirect.java | 5 +++- webapps/docs/changelog.xml | 4 +++ 6 files changed, 62 insertions(+), 12 deletions(-) diff --git a/java/org/apache/jasper/compiler/Generator.java b/java/org/apache/jasper/compiler/Generator.java index 446ac51f39..bfd2b376ae 100644 --- a/java/org/apache/jasper/compiler/Generator.java +++ b/java/org/apache/jasper/compiler/Generator.java @@ -54,6 +54,7 @@ import org.apache.jasper.TrimSpacesOption; import org.apache.jasper.compiler.Node.ChildInfoBase; import org.apache.jasper.compiler.Node.JspAttribute; import org.apache.jasper.compiler.Node.NamedAttribute; +import org.apache.jasper.compiler.Node.PageTerminationGenerator; import org.apache.jasper.runtime.JspRuntimeLibrary; import org.xml.sax.Attributes; @@ -1183,11 +1184,7 @@ class Generator { out.print(pageParam); printParams(n, pageParam, page.isLiteral()); out.println(");"); - if (isTagFile || isFragment) { - out.printil("throw new jakarta.servlet.jsp.SkipPageException();"); - } else { - out.printil((methodNesting > 0) ? "return true;" : "return;"); - } + terminatePage(); out.popIndent(); out.printil("}"); @@ -1195,6 +1192,14 @@ class Generator { // XXX Not sure if we can eliminate dead codes after this. } + private void terminatePage() { + if (isTagFile || isFragment) { + out.printil("throw new jakarta.servlet.jsp.SkipPageException();"); + } else { + out.printil((methodNesting > 0) ? "return true;" : "return;"); + } + } + @Override public void visit(Node.GetProperty n) throws JasperException { String name = n.getTextAttribute("name"); @@ -2045,6 +2050,16 @@ class Generator { } } + + @Override + public void visit(PageTerminationGenerator n) throws JasperException { + /* + * This node is a marker that the TagPluginManager needed to terminate the current page. How to do that is + * context dependent and GeneratorVisitor has the context. + */ + terminatePage(); + } + private TagHandlerInfo getTagHandlerInfo(Node.CustomTag n) throws JasperException { Map<String,TagHandlerInfo> handlerInfosByShortName = handlerInfos.computeIfAbsent(n.getPrefix(), k -> new HashMap<>()); @@ -2249,11 +2264,7 @@ class Generator { out.print(tagHandlerVar); out.println(".doEndTag() == jakarta.servlet.jsp.tagext.Tag.SKIP_PAGE) {"); out.pushIndent(); - if (isTagFile || isFragment) { - out.printil("throw new jakarta.servlet.jsp.SkipPageException();"); - } else { - out.printil((methodNesting > 0) ? "return true;" : "return;"); - } + terminatePage(); out.popIndent(); out.printil("}"); // Synchronize AT_BEGIN scripting variables diff --git a/java/org/apache/jasper/compiler/Node.java b/java/org/apache/jasper/compiler/Node.java index c9a825babb..29b749ab1f 100644 --- a/java/org/apache/jasper/compiler/Node.java +++ b/java/org/apache/jasper/compiler/Node.java @@ -2199,6 +2199,17 @@ public abstract class Node implements TagConstants { } } + /** + * Used as a placeholder for the insertion of page termination code (used by the tag plugin machinery only). + */ + public static class PageTerminationGenerator extends Node { + + @Override + void accept(Visitor v) throws JasperException { + v.visit(this); + } + } + /** * Represents the body of a <jsp:text> element */ @@ -3182,5 +3193,15 @@ public abstract class Node implements TagConstants { public void visit(AttributeGenerator n) throws JasperException { doVisit(n); } + + /** + * Visits an page termination generator node. + * + * @param n The page termination generator node to visit + * @throws JasperException if an error occurs while visiting the node + */ + public void visit(PageTerminationGenerator n) throws JasperException { + doVisit(n); + } } } diff --git a/java/org/apache/jasper/compiler/TagPluginManager.java b/java/org/apache/jasper/compiler/TagPluginManager.java index ab88b458b7..c448ad29d6 100644 --- a/java/org/apache/jasper/compiler/TagPluginManager.java +++ b/java/org/apache/jasper/compiler/TagPluginManager.java @@ -273,7 +273,11 @@ public class TagPluginManager { } return null; } - } + @Override + public void generatePageTermination() { + curNodes.add(new Node.PageTerminationGenerator()); + } + } } diff --git a/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java b/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java index 4690543575..519c732f3d 100644 --- a/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java +++ b/java/org/apache/jasper/compiler/tagplugin/TagPluginContext.java @@ -140,5 +140,12 @@ public interface TagPluginContext { * @return <code>true</code> if inside a tag file */ boolean isTagFile(); + + /** + * Generate the code to terminate the current page. + */ + default void generatePageTermination() { + throw new UnsupportedOperationException(); + } } diff --git a/java/org/apache/jasper/tagplugins/jstl/core/Redirect.java b/java/org/apache/jasper/tagplugins/jstl/core/Redirect.java index be30d71b71..fabad2c995 100644 --- a/java/org/apache/jasper/tagplugins/jstl/core/Redirect.java +++ b/java/org/apache/jasper/tagplugins/jstl/core/Redirect.java @@ -81,9 +81,12 @@ public class Redirect implements TagPlugin { // do redirect ctxt.generateJavaSource("try{"); ctxt.generateJavaSource(" " + responseName + ".sendRedirect(" + resultName + ");"); + // Avoid unreachable code error in compiler + ctxt.generateJavaSource(" if (true) {"); + ctxt.generatePageTermination(); + ctxt.generateJavaSource(" }"); ctxt.generateJavaSource("}catch(java.io.IOException ex){"); ctxt.generateJavaSource(" throw new JspTagException(ex.toString(), ex);"); ctxt.generateJavaSource("}"); } - } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 2cdda74a3e..b9e4c488fa 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -425,6 +425,10 @@ an Ant task. (sainadh777) </fix> <!-- Entries for backport and removal before 12.0.0-M1 below this line --> + <fix> + Fix the tag plugin for the JSTL <c:redirtect> tag so that page + processing ends with the redirect. (markt) + </fix> </changelog> </subsection> <subsection name="Cluster"> --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
