Skip to content

Commit d561aa1

Browse files
authored
Merge pull request #13969 from jdaugherty/7.0.x
2 parents 16b60ab + 53d5294 commit d561aa1

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ preventSnapshotPublish=false
3333
slf4jPreventExclusion=true
3434

3535
# Generated on Tue Jan 07 15:14:48 EST 2025 by: ./gradlew :grails-bom:syncProps
36-
# Only version value modifications allowed after this point. Do not insert or change version names.
36+
# Only version value modifications allowed after this point. Do not insert or change version names.
3737
ant.version=1.10.15
3838
asciidoctorj.version=3.0.0
3939
asset-pipeline-gradle.version=5.0.5

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

Lines changed: 3 additions & 5 deletions
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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,36 @@ class CommandObjectsSpec extends Specification implements ControllerUnitTest<Tes
304304
commandObject.firstName == 'Douglas'
305305
commandObject.lastName == 'Mendes'
306306
}
307+
308+
@Issue('https://github.com/grails/grails-core/issues/13945')
309+
void "calling actions involving inherited command objects - child command"() {
310+
given:
311+
params.testId = 1
312+
params.myId = 3
313+
params.pId = 2
314+
315+
when:
316+
def model = controller.zMethodTakingChild()
317+
def commandObject = model.commandObject
318+
319+
then:
320+
commandObject.testId == 1
321+
commandObject.myId == 3
322+
model.pId == 2
323+
}
324+
325+
@Issue('https://github.com/grails/grails-core/issues/13945')
326+
void "calling actions involving inherited command objects - parent command"() {
327+
given:
328+
params.testId = 1
329+
330+
when:
331+
def model = controller.methodTakingParent()
332+
def commandObject = model.commandObject
333+
334+
then:
335+
commandObject.testId == 1
336+
}
307337
}
308338

309339
@Artefact('Controller')
@@ -362,6 +392,23 @@ class TestController {
362392
def methodActionWithGenericBasedCommand(ConcreteGenericBased co) {
363393
[commandObject: co]
364394
}
395+
396+
def zMethodTakingChild(ChildCommand command, long pId) {
397+
[commandObject: command, pId: pId]
398+
}
399+
400+
def methodTakingParent(ParentCommand command) {
401+
[commandObject: command, pId: 2]
402+
}
403+
}
404+
405+
406+
class ParentCommand implements Validateable {
407+
int testId
408+
}
409+
410+
class ChildCommand extends ParentCommand {
411+
int myId
365412
}
366413

367414
class DateComamndObject {

0 commit comments

Comments
 (0)