Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-5093

Groovy Templates should treat missing variables as null rather than throw MissingPropertyException's

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.8.3
    • Fix Version/s: None
    • Component/s: Templating
    • Labels:
      None

      Description

      See Testing for nonexistent properties in groovy templates from the Groovy User list.

      SimpleTemplateEngine should evaluate ${notAlwaysAvailable == null} to true if the variable is missing from the template binding. Instead it throws: Exception in thread "main" groovy.lang.MissingPropertyException: No such property: notAlwaysAvailable for class: SimpleTemplateScript4.

      An exception in this case is not very useful, and is inconsistent with most other template implementations such as: the Java Unified Expression Language; the Spring Expression Language; FreeMarker; Velocity; and Ant, Maven and Spring property substitution.

      The binding.variables.contains("notAlwaysAvailable") workaround is overly verbose, as is having to implement your own binding or template engine.

        Attachments

          Activity

            People

            • Assignee:
              blackdrag Jochen Theodorou
              Reporter:
              ian@ianbrandt.com Ian Brandt
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: