This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new f8023d8336 Fix the tag plugin for the JSTL <c:redirtect> tag
f8023d8336 is described below

commit f8023d833675f00968b89b45639210d3c7dcc95d
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 24c9785892..c11f2d974a 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.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
@@ -1194,11 +1195,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("}");
 
@@ -1206,6 +1203,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");
@@ -2064,6 +2069,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<>());
@@ -2268,11 +2283,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 3281a40e62..edf8b1d603 100644
--- a/java/org/apache/jasper/compiler/Node.java
+++ b/java/org/apache/jasper/compiler/Node.java
@@ -2288,6 +2288,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 &lt;jsp:text&gt; element
      */
@@ -3286,5 +3297,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 2cf16df8a9..f499327c51 100644
--- a/java/org/apache/jasper/compiler/TagPluginManager.java
+++ b/java/org/apache/jasper/compiler/TagPluginManager.java
@@ -292,7 +292,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 564dcdfa75..5b6273ef8d 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -209,6 +209,10 @@
         Route <code>JspC</code> servlet context logging through Ant when used 
as
         an Ant task. (sainadh777)
       </fix>
+      <fix>
+        Fix the tag plugin for the JSTL &lt;c:redirtect&gt; 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]

Reply via email to