groovy
  1. groovy
  2. GROOVY-5101

GroovyCastException occurs since 1.8.3

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.8.5, 2.0-beta-2
    • Component/s: None
    • Labels:
      None
    • Environment:
      MacOSX: 10.6
      Groovy Version: 1.8.3
      JVM: 1.6.0_26
    • Number of attachments :
      1

      Description

      GroovyServ 0.9 doesn't work with Groovy 1.8.3. Surely, it still works well with Groovy 1.8.2.

      Stacktrace on starting-up of GroovyServ:

       2011/10/25 18:17:01.121 ---> org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'groovy.lang.Reference@464693f9' with class 'groovy.lang.Reference' to class 'java.lang.Runnable'
       2011/10/25 18:17:01.121         at org.jggug.kobo.groovyserv.RequestWorker$2.<init>(RequestWorker.groovy)
       2011/10/25 18:17:01.121         at org.jggug.kobo.groovyserv.RequestWorker.newTaskFor(RequestWorker.groovy:85)
       2011/10/25 18:17:01.121         at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:77)
       2011/10/25 18:17:01.121         at java_util_concurrent_ExecutorService$submit.callCurrent(Unknown Source)
       2011/10/25 18:17:01.121         at org.jggug.kobo.groovyserv.RequestWorker.start(RequestWorker.groovy:67)
       ...(snip)...
      

      At line 85 of RequestWorker:

      new FutureTask(runnable, defaultValue) { // anonymous inner class
          String toString() { runnable.id }
      }
      

      When I tried to fix it as following, it worked well even with groovy 1.8.3.

              new FutureTask(runnable, defaultValue)
      

      I'm sorry. I wanted to report the sample code which is independent on GroovyServ, but the problem didn't occur on the simplified sample code.

      This might be the same problem as http://jira.codehaus.org/browse/GROOVY-5077.

      GroovyServ: http://kobo.github.com/groovyserv/
      RequestWorker's full source code: https://github.com/kobo/groovyserv/blob/master/src/main/groovy/org/jggug/kobo/groovyserv/RequestWorker.groovy

        Activity

        Hide
        Yasuharu Nakano added a comment -

        I've found the commit at which the problem occurs by using git bisect at the GROOVY_1_8_x branch of groovy/groovy-core on GitHub:

        fdf212623511fce9d47d3d8ab3954a709d70583f is the first bad commit
        commit fdf212623511fce9d47d3d8ab3954a709d70583f
        Author: Jochen <blackdrag@gmx.org>
        Date: Fri Sep 9 00:04:39 2011 +0200

        GROOVY-5000: change aic constructor call to correctly respect references

        At the master branch of groovy/groovy-core on GitHub:

        commit fa995f14d52d9c0d18c19cffb448d021b29025e9
        Author: Jochen <blackdrag@gmx.org>
        Date: Fri Sep 9 00:04:39 2011 +0200

        GROOVY-5000: change aic constructor call to correctly respect references

        I made sure that the problem doesn't occur at the previous commit of it.

        For your reference, I uploaded the test script which I used for "git bisect run".
        https://gist.github.com/1313324

        Show
        Yasuharu Nakano added a comment - I've found the commit at which the problem occurs by using git bisect at the GROOVY_1_8_x branch of groovy/groovy-core on GitHub: fdf212623511fce9d47d3d8ab3954a709d70583f is the first bad commit commit fdf212623511fce9d47d3d8ab3954a709d70583f Author: Jochen <blackdrag@gmx.org> Date: Fri Sep 9 00:04:39 2011 +0200 GROOVY-5000 : change aic constructor call to correctly respect references At the master branch of groovy/groovy-core on GitHub: commit fa995f14d52d9c0d18c19cffb448d021b29025e9 Author: Jochen <blackdrag@gmx.org> Date: Fri Sep 9 00:04:39 2011 +0200 GROOVY-5000 : change aic constructor call to correctly respect references I made sure that the problem doesn't occur at the previous commit of it. For your reference, I uploaded the test script which I used for "git bisect run". https://gist.github.com/1313324
        Hide
        Yasuharu Nakano added a comment -

        the simpler test which the problem occurs

        Show
        Yasuharu Nakano added a comment - the simpler test which the problem occurs
        Yasuharu Nakano made changes -
        Field Original Value New Value
        Attachment Groovy5101Test.groovy [ 57463 ]
        Hide
        Yasuharu Nakano added a comment -

        The attached Groovy5101Test.groovy is simple enough to cause the problem, but the API of sample classes is meaningless.
        If you mind that, refer to my gist which has the improved version of test code.

        https://gist.github.com/1315245

        Show
        Yasuharu Nakano added a comment - The attached Groovy5101Test.groovy is simple enough to cause the problem, but the API of sample classes is meaningless. If you mind that, refer to my gist which has the improved version of test code. https://gist.github.com/1315245
        Hide
        Yasuharu Nakano added a comment - - edited

        I invoked the attached test code on GroovyConsole and analyzed at end of phase "Semantic Analysis" by GroovyASTBrowser.

        public void test_InnerAnonymousClass_UsingArgument() {
            java.lang.Object getClassA = { java.lang.Runnable r ->
                new Groovy5101Test$3(this, r, r) // ---> [1] 2nd and 3rd args are same as Runnable!??
            }
            assert getClassA.call(r).getSomething() == r.toString() : null
        }
        
        
        public class Groovy5101Test$3 extends Groovy5101Test$ClassA { 
        
            public groovy.lang.Reference r 
            public Groovy5101Test this$0 
        
            Groovy5101Test$3(Groovy5101Test p0, groovy.lang.Reference p1, java.lang.Object p3) { // ---[2]
                super( p3 )
                this$0 = p0 
            }
        
            public java.lang.String getSomething() {
                r.toString()
            }
        }
        

        The second parameter of Groovy5101Test$3 is Reference at [2], but the instance of Runnable was passed at [1]. So GroovyCastException occurred there.

        I guess the cause is around org.codehaus.groovy.classgen.asm.InvocationWriter#writeAICCall().

        Show
        Yasuharu Nakano added a comment - - edited I invoked the attached test code on GroovyConsole and analyzed at end of phase "Semantic Analysis" by GroovyASTBrowser. public void test_InnerAnonymousClass_UsingArgument() { java.lang. Object getClassA = { java.lang. Runnable r -> new Groovy5101Test$3( this , r, r) // ---> [1] 2nd and 3rd args are same as Runnable !?? } assert getClassA.call(r).getSomething() == r.toString() : null } public class Groovy5101Test$3 extends Groovy5101Test$ClassA { public groovy.lang.Reference r public Groovy5101Test this $0 Groovy5101Test$3(Groovy5101Test p0, groovy.lang.Reference p1, java.lang. Object p3) { // ---[2] super ( p3 ) this $0 = p0 } public java.lang. String getSomething() { r.toString() } } The second parameter of Groovy5101Test$3 is Reference at [2] , but the instance of Runnable was passed at [1] . So GroovyCastException occurred there. I guess the cause is around org.codehaus.groovy.classgen.asm.InvocationWriter#writeAICCall().
        Guillaume Laforge made changes -
        Fix Version/s 2.0-beta-2 [ 18072 ]
        Fix Version/s 1.8.5 [ 18071 ]
        Hide
        CÚdric Champeau added a comment -

        As a workaround, replace:

        ClassA getClassA3(Runnable r) {
                    new ClassA(r) {
                        String getSomething() { r.toString() }
                    }
                }
        

        with:

        ClassA getClassA3(Runnable r) {
                    new ClassA(r) {
                        String getSomething() { this.r.toString() }
                    }
                }
        
        Show
        CÚdric Champeau added a comment - As a workaround, replace: ClassA getClassA3( Runnable r) { new ClassA(r) { String getSomething() { r.toString() } } } with: ClassA getClassA3( Runnable r) { new ClassA(r) { String getSomething() { this .r.toString() } } }
        blackdrag blackdrag made changes -
        Priority Major [ 3 ] Blocker [ 1 ]
        Hide
        blackdrag blackdrag added a comment -

        the fix for GROOVY-5041 is actually almost the fix for this here too, only the wrong method to ask for the closure shared variable was used.

        Anyway, this issue is fixed, the provided est case passes now and is part of the build

        Show
        blackdrag blackdrag added a comment - the fix for GROOVY-5041 is actually almost the fix for this here too, only the wrong method to ask for the closure shared variable was used. Anyway, this issue is fixed, the provided est case passes now and is part of the build
        blackdrag blackdrag made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Assignee Jochen Theodorou [ blackdrag ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            blackdrag blackdrag
            Reporter:
            Yasuharu Nakano
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: