[ https://issues.apache.org/jira/browse/GROOVY-8881?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King resolved GROOVY-8881. ------------------------------- Resolution: Fixed Fix Version/s: 2.5.5 3.0.0-alpha-4 Should be fixed. If you can try a snapshot version, that would be great. Thanks for reporting the issue. > Inner class - qualified "this" reference cast exception inside 2 closures > ------------------------------------------------------------------------- > > Key: GROOVY-8881 > URL: https://issues.apache.org/jira/browse/GROOVY-8881 > Project: Groovy > Issue Type: Bug > Components: Compiler, groovy-runtime > Reporter: Anton Pryamostanov > Assignee: Paul King > Priority: Major > Fix For: 3.0.0-alpha-4, 2.5.5 > > > Let's consider the below example of qualified (Outer class) "this" reference > from within the Inner class, used inside a closure defined inside another > closure (2 layers of closures): > {code:java} > class OuterClass implements Runnable { > class InnerClass { > String bar() { > Closure closureOne = { > Closure closureTwo = { > OuterClass outerClassViaQualifiedThisReference = > OuterClass.this > return outerClassViaQualifiedThisReference > } > return closureTwo.call() > } > closureOne.call() > } > } > String toString() { > return "OuterClass" > } > void run() { > System.out.println(new InnerClass().bar()) > } > } > {code} > It produces the below runtime exception: > {code} > java.lang.ClassCastException: OuterClass$InnerClass cannot be cast to > OuterClass$InnerClass$_bar_closure1 > at > OuterClass$InnerClass$_bar_closure1$_closure2.doCall(ConsoleScript279:8) > at > OuterClass$InnerClass$_bar_closure1$_closure2.doCall(ConsoleScript279) > at OuterClass$InnerClass$_bar_closure1.doCall(ConsoleScript279:11) > at OuterClass$InnerClass$_bar_closure1.doCall(ConsoleScript279) > at OuterClass$InnerClass.bar(ConsoleScript279:13) > at OuterClass$InnerClass$bar.call(Unknown Source) > at OuterClass.run(ConsoleScript279:23) > {code} > However the below code runs fine (if only 1 closure is used): > {code:groovy} > class OuterClass implements Runnable { > class InnerClass { > String bar() { > Closure closureOne = { > //Closure closureTwo = { > OuterClass outerClassViaQualifiedThisReference = > OuterClass.this > return outerClassViaQualifiedThisReference > //} > //return closureTwo.call() > } > closureOne.call() > } > } > String toString() { > return "OuterClass" > } > void run() { > System.out.println(new InnerClass().bar()) > } > } > {code} > *Expected result*: > Code should run in both cases without runtime exceptions and should output > "OuterClass". -- This message was sent by Atlassian JIRA (v7.6.3#76005)