Skip to content
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

Grails 6.2.0 - Cast Exception if Action takes Command #13486

Open
jdaugherty opened this issue Apr 25, 2024 · 6 comments
Open

Grails 6.2.0 - Cast Exception if Action takes Command #13486

jdaugherty opened this issue Apr 25, 2024 · 6 comments

Comments

@jdaugherty
Copy link
Contributor

jdaugherty commented Apr 25, 2024

Expected Behavior

After upgrading to Grails 6.2.0, one of our controllers started to error. I was able to reproduce this issue in a sample application. Visiting http://localhost:8080/example/list should render the list action renders without issue. Instead an exception is thrown.

Changing a variable name in an unrelated action fixes the issue.

Actual Behaviour

A class cast exception occurs:

Cannot cast object 'brokenBinding.ExampleSearchCommand@116e5496' with class 'brokenBinding.ExampleSearchCommand' to class 'brokenBinding.ExampleCommand'

Steps To Reproduce

Details in README.md

  1. Launch grails app
  2. Visit http://localhost:8080/example/list

Environment Information

  • Operating System: Mac OS 14.4.1 & Latest Stable Linux (Debian)
  • JDK: 11.0.22 Liberica (.sdkmanrc has version in example project)

Example Application

https://github.com/jdaugherty/grails-broken-binding

Version

6.2.0

@jdaugherty
Copy link
Contributor Author

Here's a screenshot of the byte code generated by Grails for the list action that gets created to handle command object creation:

image

I've circled in red what's causing the cast exception.

@matrei
Copy link
Contributor

matrei commented Apr 25, 2024

That is interesting! Could you also post the generated code when the variable is renamed?

@jdaugherty
Copy link
Contributor Author

If I rename the variable in the edit action, here's the generated code of the list action:

image

@jdaugherty
Copy link
Contributor Author

This behavior wasn't present in our project for Grails 5.x. We first noticed it when we updated to Grails 6.x.

@rick-boardontrack
Copy link

FYI: I ran into this too.

I found that if I use the method parameter name 'cmd' for the command object, then it fails:

def save(AssessmentCommand cmd) {

produces the org.codehaus.groovy.runtime.typehandling.GroovyCastException when I call save().

But when changing the parameter named to 'acmd', everything works as expected:

def save(AssessmentCommand acmd) {

@rick-boardontrack
Copy link

I've learned a bit more... it is not JUST the name. I have another case where the name of the parameter is 'cmd' and it works just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants