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

Templating with bound variables that match class names lead to unexpected results

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.3.10
    • None
    • Templating
    • None

    Description

      I would expect that during binding, the binding occurs on supplied variables first. then after it does class lookups, but that is not what I'm finding:

      Test.groovy
      //TemplateEngine engine = new SimpleTemplateEngine()
      TemplateEngine engine = new GStringTemplateEngine()
      Template template = engine.createTemplate('This gets incorrect bindings when a binding variable name matches a classname such as ${Category} or ${String}')
      Map binding = ['Category': 'Test category', 'String': 'some string']
      String evaluated = template.make(binding)
      assert evaluated == 'This gets incorrect bindings when a binding variable name matches a classname such as Test category or some string'
      

      fails because Category gets mapped to interface groovy.lang.Category and String gets mapped to class java.lang.String
      This occurs for both GStringTemplateEngine and SimpleTemplateTemplate

      This may simply be an improper expectation on my part, but the behavior in this scenario is completely lacking from the documentation which lead to my possibly wrong expectation.

      I encountered this scenario when working on exposing the templating engine out to end-users to utilize a template to generate content for data being generated by a different team that has fairly arbitrary names and associated values.

      Honestly a bit skeptic as to this getting fixed to match the behavioral expectation I had, so instead expecting some documentation to provide clarity on the behavior going forward.

      Attachments

        Activity

          People

            Unassigned Unassigned
            steven.walters@icidigital.com Steven Walters
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: