[
https://issues.apache.org/jira/browse/FREEMARKER-234?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18034878#comment-18034878
]
Dániel Dékány edited comment on FREEMARKER-234 at 11/2/25 9:56 PM:
-------------------------------------------------------------------
That's because according to the JavaBeans spec., "is" methods are for primitive
{{boolean}}-s. For {{Boolean}} it must be a "get" method. (This is not even
enforced by FreeMarker, we just use {{java.beans.Introspector}}, which is the
official implementation of JavaBeans.)
was (Author: ddekany):
That's because according to the JavaBeans spec., "is" methods are for primitive
{{boolean}}-s. For {{Boolean}} it must be a "get" method. (This is not even
enforced by FreeMarker, we just use {{java.beans.Introspector}}, which it
official implementation of JavaBeans.)
> BeansWrapper does not expose Boolean "is" getters as properties
> ---------------------------------------------------------------
>
> Key: FREEMARKER-234
> URL: https://issues.apache.org/jira/browse/FREEMARKER-234
> Project: Apache Freemarker
> Issue Type: Bug
> Affects Versions: 2.3.34
> Environment: OpenJDK 17, Windows 10
> Reporter: John Pace
> Priority: Major
>
> According to the official
> [documentation|https://freemarker.apache.org/docs/pgui_misc_beanwrapper.html#beanswrapper_hash]:
> {quote}Every object will be wrapped into a TemplateHashModel that will expose
> JavaBeans properties and methods of the object. This way, you can use
> model.foo in the template to invoke obj.getFoo() or obj.isFoo() methods.
> {quote}
> However, this does not hold true for getters returning java.lang.Boolean.
> {code:java}
> public class MyObject {
> private Boolean obsolete = Boolean.TRUE;
> public Boolean isObsolete() {
> return obsolete;
> }
> }{code}
> {code:java}
> <!-- Works -->
> <#if myobject.isObsolete()>obsolete</#if>
> <!-- Does NOT work -->
> <#if myobject.obsolete>obsolete</#if> {code}
> {code:java}
> 19:55:46,241 ERROR f.runtime - Error executing FreeMarker template
> freemarker.core.InvalidReferenceException: The following has evaluated to
> null or missing:
> ==> myobject.obsolete [in template "templates/test.ftlh" at line 5, column
> 12]
> ----
> Tip: It's the step after the last dot that caused this error, not those
> before it.
> ----
> Tip: If the failing expression is known to legally refer to something that's
> sometimes null or missing, either specify a default value like
> myOptionalVar!myDefault, or use <#if
> myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the
> last step of the expression; to cover the whole expression, use parenthesis:
> (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)