Uploaded image for project: 'Apache Freemarker'
  1. Apache Freemarker
  2. FREEMARKER-89

Template rendering gets confused with static functinos

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Information Provided
    • 2.3.23, 2.3.27-incubating
    • None
    • engine
    • None

    Description

      I have an immutable class that shares naming for a field and a static getter:

      package org.dempsay.demo.freemaker.api;

       

       

      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;
          }
      }
      

       

      When I render it with the following template:

      The data from this sample is ${sample.data}
      

      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

       

      Attachments

        Activity

          People

            Unassigned Unassigned
            sdempsay Shawn Dempsay
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: