Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing SF 3325103: Some exceptions are not serializable

  • Loading branch information...
commit 6b1e923b2fb0a854a34bb6c15bae54f020a503f4 1 parent 901f864
@ddekany ddekany authored
View
2  build.xml
@@ -135,7 +135,7 @@
<replace
file="${_javaccOutputDir}/Token.java"
token="public class Token"
- value="class Token"
+ value="class Token implements java.io.Serializable"
/>
<replace
file="${_javaccOutputDir}/SimpleCharStream.java"
View
5 src/main/java/freemarker/template/TemplateException.java
@@ -84,7 +84,7 @@ private static boolean before14() {
/** The underlying cause of this exception, if any */
private final Exception causeException;
- private final Environment env;
+ private final transient Environment env;
private final String ftlInstructionStack;
@@ -189,7 +189,8 @@ public String getFTLInstructionStack() {
}
/**
- * @return the execution environment in which the exception occurred
+ * @return the execution environment in which the exception occurred.
+ * <tt>null</tt> if the exception was deserialized.
*/
public Environment getEnvironment() {
return env;
View
51 src/manual/book.xml
@@ -20021,6 +20021,35 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting>
</listitem>
</itemizedlist>
</section>
+
+ <section>
+ <title>Changes on the Java side</title>
+
+ <itemizedlist>
+ <listitem>
+ <para><literal>Configuration</literal> has new methods:
+ <literal>removeTemplateFromCache(...)</literal>. This will
+ remove the given template for the given locale from the cache,
+ so it will be re-loaded regardless of the template update delay
+ when it's next time requested.</para>
+ </listitem>
+
+ <listitem>
+ <para><literal>BeansWrapper</literal> ignores setter methods
+ from now when introspecting classes. They weren't used anyway,
+ so sometimes they caused
+ "<literal>java.beans.IntrospectionException</literal>: type
+ mismatch between read and write methods" errors.</para>
+ </listitem>
+
+ <listitem>
+ <para>Bug fixed <link
+ xlink:href="https://sourceforge.net/tracker/index.php?func=detail&amp;aid=3325103&amp;group_id=794&amp;atid=100794">[3325103]</link>:
+ <literal>TemplateException</literal>-s and
+ <literal>ParseException</literal>-s are now serializable.</para>
+ </listitem>
+ </itemizedlist>
+ </section>
</section>
<section xml:id="versions_2_3_18">
@@ -20154,28 +20183,6 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting>
<itemizedlist>
<listitem>
- <para><literal>Configuration</literal> has new methods:
- <literal>removeTemplateFromCache(...)</literal>. This will
- remove the given template for the given locale from the cache,
- so it will be re-loaded regardless of the template update delay
- when it's next time requested.</para>
- </listitem>
-
- <listitem>
- <para><literal>BeansWrapper</literal> ignores setter methods
- from now when introspecting classes. They weren't used anyway,
- yet sometimes they caused
- "<literal>java.beans.IntrospectionException</literal>: type
- mismatch between read and write methods" errors.</para>
- </listitem>
- </itemizedlist>
- </section>
-
- <section>
- <title>Changes on the Java side</title>
-
- <itemizedlist>
- <listitem>
<para xml:id="v2317secfix"><emphasis>Security fix</emphasis>:
Using carefully crafted template names (template paths) that
contain code point 0 (<literal>'\u0000'</literal>), it was
View
49 src/test/java/freemarker/template/ExceptionTest.java
@@ -0,0 +1,49 @@
+package freemarker.template;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.Collections;
+
+import junit.framework.TestCase;
+import freemarker.core.ParseException;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+
+public class ExceptionTest extends TestCase {
+
+ public ExceptionTest(String name) {
+ super(name);
+ }
+
+ public void testParseExceptionSerializable() throws IOException, ClassNotFoundException {
+ Configuration cfg = new Configuration();
+ try {
+ new Template("<string>", new StringReader("<@>"), cfg);
+ fail();
+ } catch (ParseException e) {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ new ObjectOutputStream(out).writeObject(e);
+ new ObjectInputStream(new ByteArrayInputStream(out.toByteArray())).readObject();
+ }
+ }
+
+ public void testTemplateErrorSerializable() throws IOException, ClassNotFoundException {
+ Configuration cfg = new Configuration();
+ Template tmp = new Template("<string>", new StringReader("${noSuchVar}"), cfg);
+ try {
+ tmp.process(Collections.EMPTY_MAP, new StringWriter());
+ fail();
+ } catch (TemplateException e) {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ new ObjectOutputStream(out).writeObject(e);
+ new ObjectInputStream(new ByteArrayInputStream(out.toByteArray())).readObject();
+ }
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.