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

Support of default methods in object model

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.3.24-incubating
    • 2.3.26-incubating
    • engine
    • None

    Description

      The default object method model currently does not support default methods:
      https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html

      Here is the current error:

      FTL stack trace ("~" means nesting-related):
      	- Failed at: #if task.switchable  [in template "...../home.ftl" at line 43, column 25]
      ----
      	at freemarker.core.InvalidReferenceException.getInstance(InvalidReferenceException.java:131)
      	at freemarker.core.UnexpectedTypeException.newDesciptionBuilder(UnexpectedTypeException.java:77)
      	at freemarker.core.UnexpectedTypeException.<init>(UnexpectedTypeException.java:40)
      	at freemarker.core.NonBooleanException.<init>(NonBooleanException.java:44)
      	at freemarker.core.Expression.modelToBoolean(Expression.java:142)
      	at freemarker.core.Expression.evalToBoolean(Expression.java:125)
      	at freemarker.core.Expression.evalToBoolean(Expression.java:110)
      	at freemarker.core.ConditionalBlock.accept(ConditionalBlock.java:46)
      	at freemarker.core.Environment.visit(Environment.java:324)
      	at freemarker.core.MixedContent.accept(MixedContent.java:54)
      	at freemarker.core.Environment.visitByHiddingParent(Environment.java:345)
      	at freemarker.core.IteratorBlock$IterationContext.executeNestedBlockInner(IteratorBlock.java:240)
      	at freemarker.core.IteratorBlock$IterationContext.executeNestedBlock(IteratorBlock.java:220)
      	at freemarker.core.IteratorBlock$IterationContext.accept(IteratorBlock.java:194)
      	at freemarker.core.Environment.visitIteratorBlock(Environment.java:572)
      	at freemarker.core.IteratorBlock.acceptWithResult(IteratorBlock.java:78)
      	at freemarker.core.IteratorBlock.accept(IteratorBlock.java:64)
      	at freemarker.core.Environment.visit(Environment.java:324)
      	at freemarker.core.MixedContent.accept(MixedContent.java:54)
      	at freemarker.core.Environment.visit(Environment.java:324)
      	at freemarker.core.Environment.process(Environment.java:302)
      	at freemarker.template.Template.process(Template.java:325)
      	at com.qwazr.tools.FreeMarkerTool.template(FreeMarkerTool.java:86)
      	at com.qwazr.tools.FreeMarkerTool.template(FreeMarkerTool.java:101)
      

      To reproduce this.

      1. Use an interface

      public interface UpdatableTask extends Runnable {
      
          default boolean isSwitchable() {
              return false;
          }
      }
      

      2. Use an object that implements this interface with the following template:

      <#if task.switchable>
      ...
      </#if>
      

      Attachments

        Activity

          People

            ddekany Dániel Dékány
            ekeller Emmanuel Keller
            Votes:
            4 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: