You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2019/04/30 02:47:00 UTC

[jira] [Comment Edited] (GROOVY-9007) Getting java.lang.NoSuchFieldError with groovy version 2.5.6

    [ https://issues.apache.org/jira/browse/GROOVY-9007?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16829900#comment-16829900 ] 

Eric Milles edited comment on GROOVY-9007 at 4/30/19 2:46 AM:
--------------------------------------------------------------

I believe this is the method of interest that was changed in 2.5.6:
{code:java}
// org.codehaus.groovy.transform.sc.transformers.VariableExpressionTransformer
    private static Expression tryTransformDelegateToProperty(VariableExpression expr) {
        // we need to transform variable expressions that go to a delegate
        // to a property expression, as ACG would loose the information
        // in processClassVariable before it reaches any makeCall, that could
        // handle it
        Object val = expr.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER);
        if (val == null) return null;
        // TODO handle the owner and delegate cases better for nested scenarios and potentially remove the need for the implicit this case
        VariableExpression receiver = new VariableExpression("owner".equals(val) ? (String) val : "delegate".equals(val) ? (String) val : "this");
        PropertyExpression pexp = new PropertyExpression(receiver, expr.getName());
        pexp.copyNodeMetaData(expr);
        pexp.setImplicitThis(true);
        pexp.getProperty().setSourcePosition(expr);
        ClassNode owner = expr.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER);
        if (owner != null) {
            receiver.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, owner);
            receiver.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, val);
        }
        return pexp;
    }
{code}

{{VariableExpression}} "it" is transformed into a {{PropertyExpression}} "owner.it".  The inferred type of the implicit parameter was saved in {{expr.getAccessedVariable()}}.  And this is not transferred to the new expression.


was (Author: emilles):
I believe this is the method of interest that was changed in 2.5.6:
{code:java}
    private static Expression tryTransformDelegateToProperty(VariableExpression expr) {
        // we need to transform variable expressions that go to a delegate
        // to a property expression, as ACG would loose the information
        // in processClassVariable before it reaches any makeCall, that could
        // handle it
        Object val = expr.getNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER);
        if (val == null) return null;
        // TODO handle the owner and delegate cases better for nested scenarios and potentially remove the need for the implicit this case
        VariableExpression receiver = new VariableExpression("owner".equals(val) ? (String) val : "delegate".equals(val) ? (String) val : "this");
        PropertyExpression pexp = new PropertyExpression(receiver, expr.getName());
        pexp.copyNodeMetaData(expr);
        pexp.setImplicitThis(true);
        pexp.getProperty().setSourcePosition(expr);
        ClassNode owner = expr.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER);
        if (owner != null) {
            receiver.putNodeMetaData(StaticTypesMarker.INFERRED_TYPE, owner);
            receiver.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, val);
        }
        return pexp;
    }
{code}

{{VariableExpression}} "it" is transformed into a {{PropertyExpression}} "owner.it".  The inferred type of the implicit parameter was saved in {{expr.getAccessedVariable()}}.  And this is not transferred to the new expression.

> Getting java.lang.NoSuchFieldError with groovy version 2.5.6
> ------------------------------------------------------------
>
>                 Key: GROOVY-9007
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9007
>             Project: Groovy
>          Issue Type: Bug
>          Components: class generator, groovy-runtime
>    Affects Versions: 2.5.6
>         Environment: Windows7, Java8, Spring-Boot 2.1.3
>            Reporter: Pankaj
>            Priority: Critical
>
> Recently, I upgrade my spring boot application with version 2.1.3. I found many test cases started failing with error {color:#d04437}(Caused by: java.lang.NoSuchFieldError: *it*){color}. After drilling down dependency list I noticed that groovy version 2.5.6 is being used. Which might be cauing these issues. Earlier it was groovy version 2.5.5 and my application was working just fine. I tried using version 2.5.5 explicitely in pom.xml and application again started working.
> This looks like a possible bug with version 2.5.6. After compaing .class file generated for both version found some difference which might be causing this issue:
> *2.5.6 generated .class code:* Here "TestGroovyNewVersion.AddressInd{color:#d04437}.it.{color}addressInd" looks incorrect as 'it' not defined as var for AddressInd enum. Here 'it' isn't getting treated as an explicit parameter for closures.
> {code:java}
> return ScriptBytecodeAdapter.compareEqual(TestGroovyNewVersion.AddressInd.it.addressInd, addressInd.get());{code}
>  
> *2.5.5 generated .class code:*
> {code:java}
> return ScriptBytecodeAdapter.compareEqual(((TestGroovyNewVersion.AddressInd)it).addressInd,addressInd.get());{code}
> +Here is my groovy code and below line of code is given error:+
> *AddressInd indicator = values().find\{ it.addressInd == addressInd }*
>  
> {code:java}
> import com.fasterxml.jackson.annotation.JsonCreator
> import groovy.transform.CompileStatic
> import groovy.transform.ToString
> @ToString
> @CompileStatic
> class TestGroovyNewVersion {
>  private enum AddressInd {
>  REGISITERED_ADD('Registered add'), TRADING_ADD('Trading add'), DELIVERY_ADD('Delivery add'), INVOICE_ADD('Invoice add')
>  protected String addressInd
>  private AddressInd(final String addressInd) {
>  this.addressInd = addressInd
>  }
>  @JsonCreator
>  static AddressInd create(final String addressInd) {
>    AddressInd indicator = values().find{ it.addressInd == addressInd }
>    if (!indicator)
>    {
>      throw new IllegalArgumentException()
>    }
>    indicator
>  }
>  }
>  String ref
>  String companyNo
>  String name
> }{code}
>  
> I would prefer to not make code changes in my code as I have similar at too many places at same time I don't want to use older version of groovy lib. Pls look into matter and suggest a solution or fix this issue if it is a possible bug in groovy 2.5.6.
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)