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

ClassicCompatible setting doesn't work with sequence built-ins as expected

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.3.30, 2.3.33
    • 2.3.34
    • None
    • None

    Description

      When turning classic compatible mode to true, usage of seq_contains, seq_index_of, seq_last_index_of built-ins becomes unstable.

      Consider the following template:

      <#setting classic_compatible=true>
      <#if eight?seq_contains(1)> </#if>

      If the next values are passed to generate a document:

      eight=[ "2", "1", "3"]

      then generation fails with the following error:
       

      Expression has thrown an unchecked exception; see the cause exception.The blamed expression:==> eight?seq_contains(1)  [in nameless template at line 2, column 6]
      ----FTL stack trace ("~" means nesting-related):	- Failed at: #if eight?seq_contains(1)  [in nameless template at line 2, column 1]----
      Caused by:java.lang.NullPointerException: null

      After further investigation it was found out that

      1) seq_ built-ins react badly on integers, whether the integer is actually contained within the sequence or not;

      2) seq_ built-ins work correctly on strings if the strings passed to built-ins is contained within the sequence, but will fail with the same NullPointerException if the string isn't contained within the sequence;

      3) it does not matter whether the built-ins are used in conditional expressions - it was tested in interpolations as well.

      This behavior was found out in versions 2.3.30 and was tested to be still present in 2.3.33.

      Is there any way to mitigate these errors upon using classic_compatible mode? Any help would be greatly appreciated.
       

      Attachments

        Activity

          People

            ddekany Dániel Dékány
            nashashok Natalia Shashok
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: