freemarker/freemarker — pull request #14 by fredrikbackstrom (2014-09-15 19:01:05+00:00)
Title: Boolean String value is empty string

In some cases the String value of a boolean expression is evaluated to "" when the boolean value is false but when the value is true it the string "true" is returned.

Note that I was playing around with FreeMarker for the first time in the context of using the result of the template for computing and not for rendering. The settings I've made to the config are what I believe should be set if you want FreeMarker for computing and not rendering, please correct me here if I got it all wrong.
I tried reading up on the usage of c? but still I think this is an error, please let me know what you think.

This snippet shows you the issue:

public static void main(String[] args) throws IOException, TemplateException {
final StringTemplateLoader stringLoader = new StringTemplateLoader();

stringLoader.putTemplate("true_expression", "${ 10 lt 11 }");
stringLoader.putTemplate("false_expression", " ${ 10 gt 11 }");

Configuration configuration = new Configuration();
configuration.setObjectWrapper(new DefaultObjectWrapper());
configuration.setDefaultEncoding("UTF-8");
configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
configuration.setTemplateLoader(stringLoader);

configuration.setIncompatibleImprovements(new Version(2, 3, 21));
configuration.setClassicCompatible(true);

StringWriter sw = new StringWriter();
Template template = configuration.getTemplate("true_expression");

template.process(new HashMap<>(), sw);

StringBuilder sb = new StringBuilder();

sb.append(sw.getBuffer());

System.out.println("true expression = " + sb.toString());

// SAME THING BUT WITH FALSE

sw = new StringWriter();
template = configuration.getTemplate("false_expression");

template.process(new HashMap<>(), sw);

sb = new StringBuilder();

sb.append(sw.getBuffer());

System.out.println("false expression = " + sb.toString());
}

output becomes

true expression = true
false expression =