FM 2.3.12: NullPointerException in BlockAssignment.getCanonicalForm() when assign body is zero length
"Klotz, Leigh" <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <E254B0A7E0268949ABFE5EA97B7D0CF404B3B449@USA7061MS01.na.xerox.net> |
Hello all; I've just joined this list, so please let me know if this
isn't the correct place to be posting .
The following template gets an error in getCanonicalForm():
---Failing Template---
<#ftl>
<#assign x></#assign>
---Test Program---
import java.io.IOException;
import freemarker.template.Configuration;
import freemarker.template.Template;
public class CanonicalTest {
public static void main(String args[]) throws IOException {
String filename = args[0];
Configuration config = new Configuration();
Template t = config.getTemplate(filename);
System.out.print(t.getRootTreeNode().getCanonicalForm());
}
}
---Execution Trace---
java -classpath
.\;c:/ds/svn1/docushare3/vendor/freemarker/freemarker.jar CanonicalTest
AssignFail.ftl
Exception in thread "main" java.lang.NullPointerException
at
freemarker.core.BlockAssignment.getCanonicalForm(BlockAssignment.java:15
0)
at
freemarker.core.MixedContent.getCanonicalForm(MixedContent.java:100)
at CanonicalTest.main(CanonicalTest.java:11)
This template will succeed:
---Passing Template---
<#ftl>
<#assign x> </#assign>
I believe freemarker-2.3.12/src/freemarker/core/BlockAssignment.java
needs to have this:
---Suggested Fix---
public String getCanonicalForm() {
...
return "<#" + key + " " + varName +
(namespaceExp != null ? " in " +
namespaceExp.getCanonicalForm() : "")
+ ">" + (nestedBlock != null ?
nestedBlock.getCanonicalForm() : "") + "</#" + key + ">";
}
Leigh.
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone