Skip to content

Commit 7c6e6da

Browse files
Fix ClassCastException
Related to #10363.
1 parent 86ffa9f commit 7c6e6da

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

grails-plugin-testing/src/main/groovy/org/grails/compiler/injection/test/TestForTransformation.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,9 @@ private IfStatement getAutowiringIfStatement(ClassExpression targetClass, Variab
459459
arguments.addExpression(new ConstantExpression(false));
460460
BlockStatement assignFromApplicationContext = new BlockStatement();
461461
ArgumentListExpression argWithClassName = new ArgumentListExpression();
462-
MethodCallExpression getClassNameMethodCall = new MethodCallExpression(targetClass, "getName", new ArgumentListExpression());
463-
argWithClassName.addExpression(getClassNameMethodCall);
462+
463+
final PropertyExpression classNamePropertyExpression = new PropertyExpression(targetClass, new ConstantExpression("name"));
464+
argWithClassName.addExpression(classNamePropertyExpression);
464465

465466
assignFromApplicationContext.addStatement(new ExpressionStatement(new BinaryExpression(fieldExpression, ASSIGN, new MethodCallExpression(appCtxVar, "getBean", argWithClassName))));
466467
BlockStatement elseBlock = new BlockStatement();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package grails.test.mixin
2+
3+
import grails.artefact.Artefact
4+
import spock.lang.Issue
5+
import spock.lang.Specification
6+
7+
@TestFor(SomeController)
8+
class TestForControllerWithNamePropertySpec extends Specification {
9+
10+
@Issue('grails/grails-core#10363')
11+
void "test referencing a controller with a 'name' property"() {
12+
when:
13+
controller
14+
15+
then:
16+
notThrown ClassCastException
17+
}
18+
}
19+
20+
@Artefact('Controller')
21+
class SomeController {
22+
String name
23+
}

0 commit comments

Comments
 (0)