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

fix #13945 - use local variable instead of casting the object #13947

Merged
merged 3 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -798,14 +798,12 @@ protected void initializeAndValidateCommandObjectParameter(final BlockStatement
}

if (argumentIsValidateable) {
final MethodCallExpression validateMethodCallExpression =
new MethodCallExpression(new VariableExpression(paramName), "validate", EMPTY_TUPLE);
final MethodNode validateMethod =
commandObjectNode.getMethod("validate", new Parameter[0]);
final MethodCallExpression validateMethodCallExpression = callX(localVarX(paramName, commandObjectNode), "validate");
final MethodNode validateMethod = commandObjectNode.getMethod("validate", new Parameter[0]);
if (validateMethod != null) {
validateMethodCallExpression.setMethodTarget(validateMethod);
}
final Statement ifCommandObjectIsNotNullThenValidate = new IfStatement(new BooleanExpression(new VariableExpression(paramName)), new ExpressionStatement(validateMethodCallExpression), new ExpressionStatement(new EmptyExpression()));
final Statement ifCommandObjectIsNotNullThenValidate = ifS(boolX(varX(paramName)), stmt(validateMethodCallExpression));
wrapper.addStatement(ifCommandObjectIsNotNullThenValidate);
} else {
// try to dynamically invoke the .validate() method if it is available at runtime...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import grails.testing.gorm.DataTest
import grails.testing.web.controllers.ControllerUnitTest
import grails.validation.Validateable
import spock.lang.Issue
import spock.lang.PendingFeature
import spock.lang.Specification

class CommandObjectsSpec extends Specification implements ControllerUnitTest<TestController>, DataTest {
Expand Down Expand Up @@ -323,7 +322,6 @@ class CommandObjectsSpec extends Specification implements ControllerUnitTest<Tes
model.pId == 2
}

@PendingFeature()
@Issue('https://github.com/grails/grails-core/issues/13945')
void "calling actions involving inherited command objects - parent command"() {
given:
Expand Down Expand Up @@ -405,7 +403,7 @@ class TestController {
}


class ParentCommand {
class ParentCommand implements Validateable {
int testId
}

Expand Down
Loading