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

AsmClassGenerator does not set source positions on property expressions

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.4.13
    • Component/s: None
    • Labels:
      None

      Description

      AsmClassGenerator.visitVariableExpression and AsmClassGenerator.processClassVariable can create a new PropertyExpression from a VariableExpression and the source position of the original is not transferred.

      Solution is pretty minimal:

       // mid way through visitVariableExpression:
              if (variable == null) {
                  // GRECLIPSE edit
                  //processClassVariable(variableName);
                  processClassVariable(expression);
                  // GRECLIPSE end
              } else {
      
          // GRECLIPSE edit
          //private void processClassVariable(String name) {
          private void processClassVariable(VariableExpression expression) {
              String name = expression.getName();
          // GRECLIPSE end
      
       // end of processClassVariable:
              } else {
                  // GRECLIPSE edit
                  //PropertyExpression pexp = new PropertyExpression(VariableExpression.THIS_EXPRESSION, name);
                  PropertyExpression pexp = new PropertyExpression(new VariableExpression("this", ClassHelper.DYNAMIC_TYPE), name);
                  pexp.getObjectExpression().setSourcePosition(expression);
                  pexp.getProperty().setSourcePosition(expression);
                  // GRECLIPSE end
                  pexp.setImplicitThis(true);
                  visitPropertyExpression(pexp);
              }
      

      I found this because I had a with expression that produced an error that was attributed to line -1.

      import com.fasterxml.jackson.annotation.JsonInclude
      import com.fasterxml.jackson.databind.ObjectMapper
      import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule
      import org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean
      @groovy.transform.CompileStatic
      final class CustomObjectMapper extends ObjectMapper
      {
          CustomObjectMapper()
          {
              super(mimicSpring())
          }
      
          private static ObjectMapper mimicSpring()
          {
              /* Formerly in SpringDispatcherContext.xml:
               *  <bean class="org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean"
               *    p:modulesToInstall="com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule"
               *    p:serializationInclusion="NON_NULL" p:failOnUnknownProperties="false"
               *    p:autoDetectFields="false" p:autoDetectGettersSetters="true">
               *  </bean>
               */
      
              new Jackson2ObjectMapperFactoryBean().with {
                  modulesToInstall = JsonOrgModule // Joda module is auto-discovered
                  serializationInclusion = JsonInclude.Include.NON_NULL
                  defaultViewInclusion = true // include w/o view tag
                  failOnUnknownProperties = false
                  autoDetectGettersSetters = true
                  autoDetectFields = false
                  afterPropertiesSet()
                  return object // error on this line; this.object is the PropertyExpression that is created by AsmClassGenerator
              }
          }
      }
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jwagenleitner John Wagenleitner
                Reporter:
                emilles Eric Milles
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: