-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClassCastException at runtime in with closure #1412
Comments
Please note this problem exists at least since Groovy 2.5.13. |
I was just looking at this sort of thing over the weekend. Your deepest closure block has "owner" the If the latest snapshot still has a problem with this after the GROOVY-9089 fix, you can add parameter to with block or event block and then use param or "it" to qualify "other" to make it explicit instead of dynamic compilation. |
Hi Eric, |
The latest snapshot includes a fix for 9089, which I discovered over the weekend had regressed. I cannot recreate your issue with current code unless I'm missing something. |
You can work around this with something like: bar.with {
addPropertyChangeListener('bar') { event ->
it.other = 'something'
println 'ok'
}
} |
Indeed, this seems to work when running the code from Eclipse with Greclipse 4.8.0.v202210241547-e2206. However, how is this supposed to go into Groovy? GROOVY-9089 is still closed. Should we open a new issue for Groovy or do you plan to reopen GROOVY-9089? |
The fix for 9089 went into the main project at the same time. It will be in the next Groovy 2.5, 3.0 and 4.0 releases. apache/groovy@dac95ae |
I have an inconsistent behaviour with code like this.
If I run this from Eclipse (using Greclipse 4.8.0.v202210232216-e2206) I get the following
ClassCastException
:If I compile and run this with Gradle/groovyc (with Groovy 2.5.19), all works fine.
What is really strange is that this is just a test case I could extract from my real project. With my real project I see the exact same exception even if I compile it with Gradle and run the application under Tomcat in the test and production environments.
A workaround is to add
@CompileDynamic
toFoo.foobar()
.The text was updated successfully, but these errors were encountered: