Kyle Moore created GROOVY-10731:
-----------------------------------

             Summary: Exceptions thrown from MarkupTemplateEngine when map 
accessors and GString interpolation are used
                 Key: GROOVY-10731
                 URL: https://issues.apache.org/jira/browse/GROOVY-10731
             Project: Groovy
          Issue Type: Bug
          Components: Templating
    Affects Versions: 4.0.4, 4.0.2, 4.0.1, 4.0.0, 4.0.5
            Reporter: Kyle Moore


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.

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

Here is a script to reproduce:

{code:groovy}
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)

''')
{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to