From users-return-3951-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Wed Feb 20 12:42:13 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 54F2A18075F for ; Wed, 20 Feb 2019 13:42:12 +0100 (CET) Received: (qmail 7146 invoked by uid 500); 20 Feb 2019 12:42:06 -0000 Mailing-List: contact users-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@groovy.apache.org Delivered-To: mailing list users@groovy.apache.org Received: (qmail 7136 invoked by uid 99); 20 Feb 2019 12:42:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Feb 2019 12:42:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id F4135189F96 for ; Wed, 20 Feb 2019 12:42:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.411 X-Spam-Level: ** X-Spam-Status: No, score=2.411 tagged_above=-999 required=6.31 tests=[DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001, URI_HEX=1.313] autolearn=disabled Authentication-Results: spamd3-us-west.apache.org (amavisd-new); dkim=pass (1024-bit key) header.d=tiscali.it Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id TC_Q8MGnmz05 for ; Wed, 20 Feb 2019 12:42:01 +0000 (UTC) Received: from smtp.tiscali.it (michael-notr.mail.tiscali.it [213.205.33.216]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTPS id D3FF060F89 for ; Wed, 20 Feb 2019 12:42:00 +0000 (UTC) Received: from [192.168.10.91] ([151.0.186.218]) by michael.mail.tiscali.it with id f0hu1z00y4j8ziF010huHM; Wed, 20 Feb 2019 12:41:54 +0000 x-auth-user: mauromol Subject: Re: Which issue do you MOST want to fix To: users@groovy.apache.org References: <1550255471508-0.post@n5.nabble.com> <1ecd6bb4-b70c-b69f-c45d-de0ccccc37c4@tiscali.it> <1550658858812-0.post@n5.nabble.com> From: Mauro Molinari Message-ID: <1da767e5-4e7f-9e38-e29b-40cbabe09494@tiscali.it> Date: Wed, 20 Feb 2019 13:41:54 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: <1550658858812-0.post@n5.nabble.com> Content-Type: multipart/alternative; boundary="------------07F44F6D379AEDC2B00C26A9" Content-Language: en-GB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tiscali.it; s=smtp; t=1550666514; bh=9p1MoKpakEk91lNbkDF5NeYTOYG6DT1DSfJgvYEIhEg=; h=Subject:To:References:From:Date:In-Reply-To; b=09mv2qcLCr9IO2ruOXDTR6zSfEF90wEEe69WSFOOM7KjIpRuIzCML8A7t5kNZ76eZ JB0vgfYju1Cl00Wj9F082Dw+Bmni21fooU38qPKf3KFBtmNFSF37f0meuCgNE6kzWz InFN7xvmOOaaUCYHqnlyp1ohRdIlXpiWFG3PK7+g= This is a multi-part message in MIME format. --------------07F44F6D379AEDC2B00C26A9 Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 8bit Hi Daniel, yes, I followed the bug report thank you! Indeed, I would have at least another GroovyCastException case when using @CompileStatic, which however is unrelated to that fix. I can easily reproduce with a project we use internally, which is however tightly bound to our internal services. Today I spent almost two hours to try to isolate the problem in a self-contained test case, but I could not succeed :-( Any idea on what path I may follow to help you further investigate the problem? The code breaks at a point like this: |@CompileStatic|| | |public MyClass {| |� // [...]|| | | | |� private static Foo createFoo(final String type, final Object value) {| |� � if(!type || !value) || | |�� �� return null;| |� � def result = new Foo()| |� � result.with {| |�� �� beginUpdate()| |�� �� try {| |�� ���� prop1 = anotherStaticMethodReturningString('blah')| |�� ���� if(value instanceof String)| |�� ������ prop2 = anotherStaticMethodReturningString('oh')| |�� ���� else if (value instanceof BigDecimal)| |�� ������ prop3 = (BigDecimal) value| |�� ��� // else if - other cases of instanceof|| | |�� �� } finally {| |�� ���� endUpdate()|| | |�� �� }|| | |� � }| |� � return result;|| | |� }| | | |� // [...]|| | |}|| | where: * |Foo| is a Java class coming from a JAR * |beginUpdate()| and |endUpdate()| are methods defined in |Foo| * |prop1|, |prop2| and |prop3| are properties defined in |Foo| (i.e.: there are getters and setters for them) The exception occurs at the invocation of |endUpdate()| with the following exception: |org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'class test.MyClass' with class 'java.lang.Class' to class 'anotherpackage.Foo'|| ||��� at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:414)|| ||��� at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:328)|| ||��� at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:242)|| ||��� at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:615)|| ||��� at test.MyClass$_createFoo_closure6.doCall(MyClass.groovy:295)|| ||��� at test.MyClass$_createFoo_closure6.call(MyClass.groovy)|| ||��� at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:369)|| ||��� at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:316)|| ||��� at test.MyClass.createFoo(MyClass.groovy:275)| So, it seems like it's trying to invoke |endUpdate()| on |MyClass| class instance rather than on the |Foo| instance to which |with| should delegate to. The problem goes away if either: * I remove |@CompileStatic| (or I just add |@CompileDynamic| to |createFoo()| method)|| * I apply to |MyClass| (or maybe to the consumer code using |MyClass|) a sufficient amount of changes (but I can't say exactly which ones)| | Any idea? Mauro Il 20/02/2019 11:34, Daniel Sun ha scritto: > Hi Mauro, > > The issue you most want to fix is fixed: > https://github.com/apache/groovy/commit/f44449ebd615cb5d5f766a30b2a6e904084acece > > Cheers, > Daniel.Sun > > > > > -- > Sent from: http://groovy.329449.n5.nabble.com/Groovy-Users-f329450.html --------------07F44F6D379AEDC2B00C26A9 Content-Type: text/html; charset=iso-8859-15 Content-Transfer-Encoding: 8bit
Hi Daniel,
yes, I followed the bug report thank you!
Indeed, I would have at least another GroovyCastException case when using @CompileStatic, which however is unrelated to that fix. I can easily reproduce with a project we use internally, which is however tightly bound to our internal services. Today I spent almost two hours to try to isolate the problem in a self-contained test case, but I could not succeed :-(

Any idea on what path I may follow to help you further investigate the problem?

The code breaks at a point like this:

@CompileStatic
public MyClass {
� // [...]

� private static Foo createFoo(final String type, final Object value) {
� � if(!type || !value)
�� �� return null;
� � def result = new Foo()
� � result.with {
�� �� beginUpdate()
�� �� try {
�� ���� prop1 = anotherStaticMethodReturningString('blah')
�� ���� if(value instanceof String)
�� ������ prop2 = anotherStaticMethodReturningString('oh')
�� ���� else if (value instanceof BigDecimal)
�� ������ prop3 = (BigDecimal) value
�� ��� // else if - other cases of instanceof
�� �� } finally {
�� ���� endUpdate()
�� �� }
� � }
� � return result;
� }

� // [...]
}

where:
  • Foo is a Java class coming from a JAR
  • beginUpdate() and endUpdate() are methods defined in Foo
  • prop1, prop2 and prop3 are properties defined in Foo (i.e.: there are getters and setters for them)

The exception occurs at the invocation of endUpdate() with the following exception:

org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'class test.MyClass' with class 'java.lang.Class' to class 'anotherpackage.Foo'
��� at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnSAM(DefaultTypeTransformation.java:414)
��� at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.continueCastOnNumber(DefaultTypeTransformation.java:328)
��� at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToType(DefaultTypeTransformation.java:242)
��� at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.castToType(ScriptBytecodeAdapter.java:615)
��� at test.MyClass$_createFoo_closure6.doCall(MyClass.groovy:295)
��� at test.MyClass$_createFoo_closure6.call(MyClass.groovy)
��� at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:369)
��� at org.codehaus.groovy.runtime.DefaultGroovyMethods.with(DefaultGroovyMethods.java:316)
��� at test.MyClass.createFoo(MyClass.groovy:275)

So, it seems like it's trying to invoke endUpdate() on MyClass class instance rather than on the Foo instance to which with should delegate to.

The problem goes away if either:
  • I remove @CompileStatic (or I just add @CompileDynamic to createFoo() method)
  • I apply to MyClass (or maybe to the consumer code using MyClass) a sufficient amount of changes (but I can't say exactly which ones)
Any idea?

Mauro

Il 20/02/2019 11:34, Daniel Sun ha scritto:
Hi Mauro,

The issue you most want to fix is fixed:
https://github.com/apache/groovy/commit/f44449ebd615cb5d5f766a30b2a6e904084acece

Cheers,
Daniel.Sun




--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Users-f329450.html


--------------07F44F6D379AEDC2B00C26A9--