You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by "Shawn Dempsay (JIRA)" <ji...@apache.org> on 2018/02/17 14:37:00 UTC

[jira] [Commented] (FREEMARKER-89) Template rendering gets confused with static functinos

    [ https://issues.apache.org/jira/browse/FREEMARKER-89?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16368222#comment-16368222 ] 

Shawn Dempsay commented on FREEMARKER-89:
-----------------------------------------

I found a way to work around it with a fine tuner method, I guess maybe this is the only way to deal with the situation?


{code:java}
 public class StaticMethodTuner implements MethodAppearanceFineTuner {
    @Override
    public void process(final MethodAppearanceDecisionInput in, final MethodAppearanceDecision out) {
        if (Modifier.isStatic(in.getMethod().getModifiers())) {
            out.setExposeMethodAs(String.format("static_%s", out.getExposeMethodAs()));
        }
    }
}
{code}


> Template rendering gets confused with static functinos
> ------------------------------------------------------
>
>                 Key: FREEMARKER-89
>                 URL: https://issues.apache.org/jira/browse/FREEMARKER-89
>             Project: Apache Freemarker
>          Issue Type: Bug
>          Components: engine
>    Affects Versions: 2.3.23, 2.3.27-incubating
>            Reporter: Shawn Dempsay
>            Priority: Major
>
> I have an immutable class that shares naming for a field and a static getter:
> package org.dempsay.demo.freemaker.api;
>  
>  
> {code:java}
> public class Sample {
>     public final String data;
>     protected Sample(final SampleBuilder builder) {
>         this.data = builder.data;
>     }
>     public static String data(final Sample sample) {
>         return sample.data;
>     }
> }
> {code}
>  
> When I render it with the following template:
> {code:java}
> The data from this sample is ${sample.data}
> {code}
> I get this error:
> Feb 17, 2018 7:59:40 AM freemarker.log._JULLoggerFactory$JULLogger error
> SEVERE: Error executing FreeMarker template
> FreeMarker template error:
> For "${...}" content: Expected a string or something automatically convertible to string (number, date or boolean), or "template output" , but this has evaluated to a method+sequence (wrapper: f.e.b.SimpleMethodModel):
> ==> sample.data  [in template "sample.ftl" at line 1, column 32]
>  
> ----
> Tip: Maybe using obj.something(params) instead of obj.something will yield the desired value
> ----
>  
> ----
> FTL stack trace ("~" means nesting-related):
> - Failed at: ${sample.data}  [in template "sample.ftl" at line 1, column 30]
> ----
>  
> The full code for this is posted in github at: https://github.com/sdempsay/freemarker-bug
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)