Skip to content

Commit 0a32dcd

Browse files
authored
Merge pull request #13947 from jdaugherty/6.2.x
fix #13945 - use local variable instead of casting the object
2 parents e8a07aa + 33b3dc1 commit 0a32dcd

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

grails-plugin-controllers/src/main/groovy/org/grails/compiler/web/ControllerActionTransformer.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -798,14 +798,12 @@ protected void initializeAndValidateCommandObjectParameter(final BlockStatement
798798
}
799799

800800
if (argumentIsValidateable) {
801-
final MethodCallExpression validateMethodCallExpression =
802-
new MethodCallExpression(new VariableExpression(paramName), "validate", EMPTY_TUPLE);
803-
final MethodNode validateMethod =
804-
commandObjectNode.getMethod("validate", new Parameter[0]);
801+
final MethodCallExpression validateMethodCallExpression = callX(localVarX(paramName, commandObjectNode), "validate");
802+
final MethodNode validateMethod = commandObjectNode.getMethod("validate", new Parameter[0]);
805803
if (validateMethod != null) {
806804
validateMethodCallExpression.setMethodTarget(validateMethod);
807805
}
808-
final Statement ifCommandObjectIsNotNullThenValidate = new IfStatement(new BooleanExpression(new VariableExpression(paramName)), new ExpressionStatement(validateMethodCallExpression), new ExpressionStatement(new EmptyExpression()));
806+
final Statement ifCommandObjectIsNotNullThenValidate = ifS(boolX(varX(paramName)), stmt(validateMethodCallExpression));
809807
wrapper.addStatement(ifCommandObjectIsNotNullThenValidate);
810808
} else {
811809
// try to dynamically invoke the .validate() method if it is available at runtime...

grails-test-suite-web/src/test/groovy/org/grails/web/commandobjects/CommandObjectsSpec.groovy

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import grails.testing.gorm.DataTest
55
import grails.testing.web.controllers.ControllerUnitTest
66
import grails.validation.Validateable
77
import spock.lang.Issue
8-
import spock.lang.PendingFeature
98
import spock.lang.Specification
109

1110
class CommandObjectsSpec extends Specification implements ControllerUnitTest<TestController>, DataTest {
@@ -323,7 +322,6 @@ class CommandObjectsSpec extends Specification implements ControllerUnitTest<Tes
323322
model.pId == 2
324323
}
325324

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

407405

408-
class ParentCommand {
406+
class ParentCommand implements Validateable {
409407
int testId
410408
}
411409

0 commit comments

Comments
 (0)