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

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

commit 4a19042d4c2eab09a46c8506aa9f3784e8dfdce4
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu May 13 16:46:56 2021 +0100

    Refactor to use compile time rather than run time type checking
---
 java/org/apache/jasper/compiler/Generator.java     | 21 +++-------
 java/org/apache/jasper/compiler/Node.java          | 45 ++++++++++------------
 .../jasper/resources/LocalStrings.properties       |  1 -
 .../jasper/resources/LocalStrings_de.properties    |  1 -
 .../jasper/resources/LocalStrings_fr.properties    |  1 -
 .../jasper/resources/LocalStrings_ja.properties    |  1 -
 .../jasper/resources/LocalStrings_ko.properties    |  1 -
 .../jasper/resources/LocalStrings_zh_CN.properties |  1 -
 webapps/docs/changelog.xml                         |  4 ++
 9 files changed, 29 insertions(+), 47 deletions(-)

diff --git a/java/org/apache/jasper/compiler/Generator.java 
b/java/org/apache/jasper/compiler/Generator.java
index fbe1d96..a3b73d3 100644
--- a/java/org/apache/jasper/compiler/Generator.java
+++ b/java/org/apache/jasper/compiler/Generator.java
@@ -52,6 +52,7 @@ import org.apache.el.util.JreCompat;
 import org.apache.jasper.Constants;
 import org.apache.jasper.JasperException;
 import org.apache.jasper.JspCompilationContext;
+import org.apache.jasper.compiler.Node.ChildInfoBase;
 import org.apache.jasper.compiler.Node.NamedAttribute;
 import org.apache.jasper.runtime.JspRuntimeLibrary;
 import org.xml.sax.Attributes;
@@ -3262,8 +3263,7 @@ class Generator {
          * Generates anonymous JspFragment inner class which is passed as an
          * argument to SimpleTag.setJspBody().
          */
-        private void generateJspFragment(Node n, String tagHandlerVar)
-                throws JasperException {
+        private void generateJspFragment(ChildInfoBase n, String 
tagHandlerVar) throws JasperException {
             // XXX - A possible optimization here would be to check to see
             // if the only child of the parent node is TemplateText. If so,
             // we know there won't be any parameters, etc, so we can
@@ -3377,18 +3377,8 @@ class Generator {
         }
     }
 
-    private static void generateLocalVariables(ServletWriter out, Node n)
-            throws JasperException {
-        Node.ChildInfo ci;
-        if (n instanceof Node.CustomTag) {
-            ci = ((Node.CustomTag) n).getChildInfo();
-        } else if (n instanceof Node.JspBody) {
-            ci = ((Node.JspBody) n).getChildInfo();
-        } else if (n instanceof Node.NamedAttribute) {
-            ci = ((Node.NamedAttribute) n).getChildInfo();
-        } else {
-            throw new 
JasperException(Localizer.getMessage("jsp.error.internal.unexpectedNodeType"));
-        }
+    private static void generateLocalVariables(ServletWriter out, 
ChildInfoBase n) {
+        Node.ChildInfo ci = n.getChildInfo();
 
         if (ci.hasUseBean()) {
             out.printil("javax.servlet.http.HttpSession session = 
_jspx_page_context.getSession();");
@@ -4223,8 +4213,7 @@ class Generator {
             out.printil("}");
         }
 
-        public Fragment openFragment(Node parent, int methodNesting)
-        throws JasperException {
+        public Fragment openFragment(ChildInfoBase parent, int methodNesting) {
             Fragment result = new Fragment(fragments.size(), parent);
             fragments.add(result);
             this.used = true;
diff --git a/java/org/apache/jasper/compiler/Node.java 
b/java/org/apache/jasper/compiler/Node.java
index 67ff2b9..92b4a96 100644
--- a/java/org/apache/jasper/compiler/Node.java
+++ b/java/org/apache/jasper/compiler/Node.java
@@ -1398,10 +1398,27 @@ abstract class Node implements TagConstants {
         }
     }
 
+
+    public abstract static class ChildInfoBase extends Node {
+
+        private final ChildInfo childInfo = new ChildInfo();
+
+        public ChildInfoBase(String qName, String localName, Attributes attrs,
+                Attributes nonTaglibXmlnsAttrs, Attributes taglibAttrs, Mark 
start,
+                Node parent) {
+            super(qName, localName, attrs, nonTaglibXmlnsAttrs, taglibAttrs, 
start, parent);
+        }
+
+        public ChildInfo getChildInfo() {
+            return childInfo;
+        }
+    }
+
+
     /**
      * Represents a custom tag
      */
-    public static class CustomTag extends Node {
+    public static class CustomTag extends ChildInfoBase {
 
         private final String uri;
 
@@ -1423,8 +1440,6 @@ abstract class Node implements TagConstants {
 
         private final int customNestingLevel;
 
-        private final ChildInfo childInfo;
-
         private final boolean implementsIterationTag;
 
         private final boolean implementsBodyTag;
@@ -1487,7 +1502,6 @@ abstract class Node implements TagConstants {
             this.tagFileInfo = null;
             this.tagHandlerClass = tagHandlerClass;
             this.customNestingLevel = makeCustomNestingLevel();
-            this.childInfo = new ChildInfo();
 
             this.implementsIterationTag = IterationTag.class
                     .isAssignableFrom(tagHandlerClass);
@@ -1529,7 +1543,6 @@ abstract class Node implements TagConstants {
             this.tagFileInfo = tagFileInfo;
             this.tagInfo = tagFileInfo.getTagInfo();
             this.customNestingLevel = makeCustomNestingLevel();
-            this.childInfo = new ChildInfo();
 
             this.implementsIterationTag = false;
             this.implementsBodyTag = false;
@@ -1566,10 +1579,6 @@ abstract class Node implements TagConstants {
             return jspAttrs;
         }
 
-        public ChildInfo getChildInfo() {
-            return childInfo;
-        }
-
         public void setTagData(TagData tagData) {
             this.tagData = tagData;
             this.varInfos = tagInfo.getVariableInfo(tagData);
@@ -1865,7 +1874,7 @@ abstract class Node implements TagConstants {
     /**
      * Represents a Named Attribute (&lt;jsp:attribute&gt;)
      */
-    public static class NamedAttribute extends Node {
+    public static class NamedAttribute extends ChildInfoBase {
 
         // A unique temporary variable name suitable for code generation
         private String temporaryVariableName;
@@ -1877,8 +1886,6 @@ abstract class Node implements TagConstants {
         // used with a <jsp:element>, otherwise false
         private JspAttribute omit;
 
-        private final ChildInfo childInfo;
-
         private final String name;
 
         private String localName;
@@ -1899,7 +1906,6 @@ abstract class Node implements TagConstants {
                 // (if null or true, leave default of true)
                 trim = false;
             }
-            childInfo = new ChildInfo();
             name = this.getAttributeValue("name");
             if (name != null) {
                 // Mandatory attribute "name" will be checked in Validator
@@ -1930,10 +1936,6 @@ abstract class Node implements TagConstants {
             return this.prefix;
         }
 
-        public ChildInfo getChildInfo() {
-            return this.childInfo;
-        }
-
         public boolean isTrim() {
             return trim;
         }
@@ -1998,9 +2000,7 @@ abstract class Node implements TagConstants {
     /**
      * Represents a JspBody node (&lt;jsp:body&gt;)
      */
-    public static class JspBody extends Node {
-
-        private final ChildInfo childInfo;
+    public static class JspBody extends ChildInfoBase {
 
         public JspBody(Mark start, Node parent) {
             this(JSP_BODY_ACTION, null, null, start, parent);
@@ -2010,17 +2010,12 @@ abstract class Node implements TagConstants {
                 Attributes taglibAttrs, Mark start, Node parent) {
             super(qName, BODY_ACTION, null, nonTaglibXmlnsAttrs, taglibAttrs,
                     start, parent);
-            this.childInfo = new ChildInfo();
         }
 
         @Override
         public void accept(Visitor v) throws JasperException {
             v.visit(this);
         }
-
-        public ChildInfo getChildInfo() {
-            return childInfo;
-        }
     }
 
     /**
diff --git a/java/org/apache/jasper/resources/LocalStrings.properties 
b/java/org/apache/jasper/resources/LocalStrings.properties
index c5ed7fe..eb8b0b3 100644
--- a/java/org/apache/jasper/resources/LocalStrings.properties
+++ b/java/org/apache/jasper/resources/LocalStrings.properties
@@ -81,7 +81,6 @@ jsp.error.function.classnotfound=The class [{0}] specified in 
TLD for the functi
 jsp.error.include.exception=Unable to include [{0}]
 jsp.error.include.tag=Invalid jsp:include tag
 jsp.error.internal.filenotfound=Internal Error: File [{0}] not found
-jsp.error.internal.unexpectedNodeType=Unexpected node type
 jsp.error.invalid.attribute=[{0}] has invalid attribute: [{1}]
 jsp.error.invalid.bean=The value for the useBean class attribute [{0}] is 
invalid.
 jsp.error.invalid.directive=Invalid directive
diff --git a/java/org/apache/jasper/resources/LocalStrings_de.properties 
b/java/org/apache/jasper/resources/LocalStrings_de.properties
index cd15d94..da263ad 100644
--- a/java/org/apache/jasper/resources/LocalStrings_de.properties
+++ b/java/org/apache/jasper/resources/LocalStrings_de.properties
@@ -30,7 +30,6 @@ jsp.error.el.template.deferred=#{...} is im Template Text 
nicht erlaubt
 jsp.error.fallback.invalidUse=jsp:fallback muss ein direktes Kind von 
jsp:plugin sein
 jsp.error.file.not.found=Datei [{0}] nicht gefunden
 jsp.error.internal.filenotfound=Interner Fehler: Datei [{0}] nicht gefunden
-jsp.error.internal.unexpectedNodeType=Unerwarteter Knotentyp
 jsp.error.invalid.attribute=[{0}] hat ein ungültiges Attribut: [{1}]
 jsp.error.invalid.tagdir=Tag Verzeichnis [{0}] beginnt nicht mit 
"/WEB-INF/tags"
 jsp.error.invalid.version=Ungültige JSP Version für tag-Datei in [{0}] 
definiert
diff --git a/java/org/apache/jasper/resources/LocalStrings_fr.properties 
b/java/org/apache/jasper/resources/LocalStrings_fr.properties
index 4eaf55e..9419b02 100644
--- a/java/org/apache/jasper/resources/LocalStrings_fr.properties
+++ b/java/org/apache/jasper/resources/LocalStrings_fr.properties
@@ -81,7 +81,6 @@ jsp.error.function.classnotfound=La classe [{0}] spécifiée 
dans la TLD pour la
 jsp.error.include.exception=Impossible d''inclure (include) [{0}]
 jsp.error.include.tag=Tag jsp:include incorrect
 jsp.error.internal.filenotfound=Erreur interne : Fichier [{0}] introuvable
-jsp.error.internal.unexpectedNodeType=Type de nœud inattendu
 jsp.error.invalid.attribute=[{0}] : Attribut incorrect : [{1}]
 jsp.error.invalid.bean=La valeur [{0}] de l''attribut de classe useBean est 
invalide
 jsp.error.invalid.directive=Directive incorrecte
diff --git a/java/org/apache/jasper/resources/LocalStrings_ja.properties 
b/java/org/apache/jasper/resources/LocalStrings_ja.properties
index cfe97a2..083742c 100644
--- a/java/org/apache/jasper/resources/LocalStrings_ja.properties
+++ b/java/org/apache/jasper/resources/LocalStrings_ja.properties
@@ -82,7 +82,6 @@ jsp.error.function.classnotfound=TLDの中で関数 [{1}] に指定されてい
 jsp.error.include.exception=[{0}] を include 出来ません
 jsp.error.include.tag=無効なjsp:includeタグです
 jsp.error.internal.filenotfound=内部エラー: ファイル [{0}] が見つかりません
-jsp.error.internal.unexpectedNodeType=予想外のノードタイプ
 jsp.error.invalid.attribute=[{0}]は無効な属性を持っています: [{1}]
 jsp.error.invalid.bean=useBeanのクラス属性 [{0}] の値が無効です
 jsp.error.invalid.directive=無効なディレクティブ
diff --git a/java/org/apache/jasper/resources/LocalStrings_ko.properties 
b/java/org/apache/jasper/resources/LocalStrings_ko.properties
index 18b0928..54c1d67 100644
--- a/java/org/apache/jasper/resources/LocalStrings_ko.properties
+++ b/java/org/apache/jasper/resources/LocalStrings_ko.properties
@@ -82,7 +82,6 @@ jsp.error.function.classnotfound=function [{1}]을(를) 위하여 TLD에 
지정
 jsp.error.include.exception=[{0}]을(를) include할 수 없습니다.
 jsp.error.include.tag=유효하지 않은 jsp:include 태그
 jsp.error.internal.filenotfound=내부 오류: 파일 [{0}]을(를) 찾을 수 없습니다.
-jsp.error.internal.unexpectedNodeType=예기치 않은 노드 타입
 jsp.error.invalid.attribute=[{0}]은(는) 유효하지 않은 속성을 가지고 있습니다: [{1}]
 jsp.error.invalid.bean=useBean의 class 속성을 위한 값 [{0}]은(는) 유효하지 않습니다.
 jsp.error.invalid.directive=유효하지 않은 지시어
diff --git a/java/org/apache/jasper/resources/LocalStrings_zh_CN.properties 
b/java/org/apache/jasper/resources/LocalStrings_zh_CN.properties
index 923d970..0248248 100644
--- a/java/org/apache/jasper/resources/LocalStrings_zh_CN.properties
+++ b/java/org/apache/jasper/resources/LocalStrings_zh_CN.properties
@@ -81,7 +81,6 @@ jsp.error.function.classnotfound=找不到在TLD中为函数[{1}]指定的类[{0
 jsp.error.include.exception=无法包含[{0}]
 jsp.error.include.tag=无效的jsp:include标签
 jsp.error.internal.filenotfound=内部错误:找不到文件 [{0}]
-jsp.error.internal.unexpectedNodeType=节点类型不一致
 jsp.error.invalid.attribute=[{0}]有一个无效属性:[{1}]
 jsp.error.invalid.bean=useBean类属性[{0}]的值无效。
 jsp.error.invalid.directive=无效指令
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 849cbc1..9b34c65 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -119,6 +119,10 @@
         Review code used to generate Java source from JSPs and tags and remove
         code found to be unnecessary. (markt)
       </scode>
+      <scode>
+        Refactor use of internal <code>ChildInfo</code> class to use compile
+        time type checking rather than run time type checking. (markt)
+      </scode>
     </changelog>
   </subsection>
 </section>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to