Bug fixed (FREEMARKER-88): This is related to calling JSP tags from templates. 
If a TemplateException that's not a TemplateModelExceptoin has occurred in the 
body of a JSP SimpleTag (typically, an InvalidReferenceException), that has 
caused a ClassCastException in the exception handling code, thus the template 
processing has thrown that instead of the original exception.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/5f4b7f35
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/5f4b7f35
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/5f4b7f35

Branch: refs/heads/2.3
Commit: 5f4b7f354d29263d14e9bffbe3c2cc6829222878
Parents: ae24152
Author: ddekany <ddek...@apache.org>
Authored: Sat Feb 3 22:14:45 2018 +0100
Committer: ddekany <ddek...@apache.org>
Committed: Sat Feb 3 22:14:45 2018 +0100

----------------------------------------------------------------------
 src/main/java/freemarker/ext/jsp/JspTagModelBase.java  |  2 +-
 .../freemarker/ext/jsp/SimpleTagDirectiveModel.java    |  8 +++++++-
 src/manual/en_US/book.xml                              | 13 +++++++++++++
 3 files changed, 21 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/5f4b7f35/src/main/java/freemarker/ext/jsp/JspTagModelBase.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/jsp/JspTagModelBase.java 
b/src/main/java/freemarker/ext/jsp/JspTagModelBase.java
index 7d72df5..83c0104 100644
--- a/src/main/java/freemarker/ext/jsp/JspTagModelBase.java
+++ b/src/main/java/freemarker/ext/jsp/JspTagModelBase.java
@@ -143,7 +143,7 @@ class JspTagModelBase {
             throw (TemplateModelException) e;
         }
         if (e instanceof TemplateExceptionWrapperJspException) {
-            return (TemplateModelException) e.getCause();
+            return 
toTemplateModelExceptionOrRethrow(((TemplateExceptionWrapperJspException) 
e).getCause());
         }
         return new _TemplateModelException(e,
                 "Error while invoking the ", new _DelayedJQuote(tagName), " 
JSP custom tag; see cause exception");

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/5f4b7f35/src/main/java/freemarker/ext/jsp/SimpleTagDirectiveModel.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/jsp/SimpleTagDirectiveModel.java 
b/src/main/java/freemarker/ext/jsp/SimpleTagDirectiveModel.java
index 882456e..e02e4c9 100644
--- a/src/main/java/freemarker/ext/jsp/SimpleTagDirectiveModel.java
+++ b/src/main/java/freemarker/ext/jsp/SimpleTagDirectiveModel.java
@@ -94,6 +94,8 @@ class SimpleTagDirectiveModel extends JspTagModelBase 
implements TemplateDirecti
             } finally {
                 pageContext.popWriter();
             }
+        } catch (TemplateException e) {
+            throw e;
         } catch (Exception e) {
             throw toTemplateModelExceptionOrRethrow(e);
         }
@@ -101,10 +103,14 @@ class SimpleTagDirectiveModel extends JspTagModelBase 
implements TemplateDirecti
     
     static final class TemplateExceptionWrapperJspException extends 
JspException {
 
-        public TemplateExceptionWrapperJspException(Throwable cause) {
+        public TemplateExceptionWrapperJspException(TemplateException cause) {
             super("Nested content has thrown template exception", cause);
         }
         
+        public TemplateException getCause() {
+            return (TemplateException) super.getCause();
+        }
+        
     }
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/5f4b7f35/src/manual/en_US/book.xml
----------------------------------------------------------------------
diff --git a/src/manual/en_US/book.xml b/src/manual/en_US/book.xml
index aa509de..7325bd0 100644
--- a/src/manual/en_US/book.xml
+++ b/src/manual/en_US/book.xml
@@ -27110,6 +27110,19 @@ TemplateModel x = env.getVariable("x");  // get 
variable x</programlisting>
 
           <itemizedlist>
             <listitem>
+              <para>Bug fixed (<link
+              
xlink:href="https://issues.apache.org/jira/browse/FREEMARKER-88";>FREEMARKER-88</link>):
+              This is related to calling JSP tags from templates. If a
+              <literal>TemplateException</literal> that's not a
+              <literal>TemplateModelExceptoin</literal> has occurred in the
+              body of a JSP <literal>SimpleTag</literal> (typically, an
+              <literal>InvalidReferenceException</literal>), that has caused a
+              <literal>ClassCastException</literal> in the exception handling
+              code, thus the template processing has thrown that instead of
+              the original exception.</para>
+            </listitem>
+
+            <listitem>
               <para>Added new property to
               <literal>BeansWrapper.MethodAppearanceDecision</literal>:
               <literal>replaceExistingProperty</literal>. This is useful when

Reply via email to