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

Exceptions thrown from MarkupTemplateEngine when map accessors and GString interpolation are used

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.0, 4.0.1, 4.0.2, 4.0.4, 4.0.5
    • 4.0.5, 2.5.19, 3.0.13
    • Templating
    • None

    Description

      I've observed some breaking behavior beginning with v4.0.0 and continuing through the latest 4.0.5-SNAPSHOT. All examples below pass in v3.0.12.

      This is a simplification of errors seen when using the japicmp-gradle-plugin v3.0.0 inside the Gradle build; specifically its use of this template to create a HTML report.

      There are three different error messages produced, illustrated by the three examples below: [mapLookup, nestedGString, noGString]

      Here is a script to reproduce:

      import groovy.text.markup.MarkupTemplateEngine;
      import groovy.text.markup.TemplateConfiguration;
      
      
      def tryTemplate(name, template) {
          TemplateConfiguration templateConfiguration = new TemplateConfiguration();
          templateConfiguration.setAutoNewLine(true); // Removing this fixes nestedGString
          MarkupTemplateEngine engine = new MarkupTemplateEngine(templateConfiguration);    
          try {
              println("Trying $name")
              engine.createTemplate(template)
          } catch (Throwable e) {
              println(e.message)
          }
      }
      
      tryTemplate('mapLookup', '''
      def severityMappings = [:]
      String err = ""
      
      // 1. these two lines fail
      // produces a java.lang.ArrayIndexOutOfBoundsException: size==0
      def foo = severityMappings[err]
      span(class: "label label-${foo}")  
      
      ''')
      
      tryTemplate('nestedGString', '''
      def severityMappings = [:]
      String err = ""
      
      // 2. just the span line fails
      // throws groovy.lang.GroovyRuntimeException: ASM reporting processing error for GeneratedMarkupTemplate121$_run_closure1#doCall with signature java.lang.Object doCall(java.lang.Object) in GeneratedMarkupTemplate121:12. GeneratedMarkupTemplate121
      html {
          span(class: "label label-${severityMappings[err]}")
      }
      ''')
      
      tryTemplate('noGString', '''
      def severityMappings = [:]
      String err = ""
      
      // 3. no GString interpolation fails
      // BUG! exception in phase 'class generation' in source unit 'GeneratedMarkupTemplate82' Error while popping argument from operand stack tracker in class
      def foo = "label label-" + severityMappings[err]
      span(class: foo)
      
      ''')
      

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              DPUkyle Kyle Moore
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: