Skip to content

Commit 94286c4

Browse files
committed
Recognize properties with the second letter capitalized
Make ClassPropertyFetcher also recognize properties of the form "xAge" that have the second letter capitalized. Fixes #10403
1 parent 0dfdd0a commit 94286c4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

grails-core/src/main/groovy/org/grails/core/util/ClassPropertyFetcher.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,10 @@ public void doWith(CachedMethod method) throws IllegalArgumentException,
130130
if (method.getParameterTypes().length == 0) {
131131
String name = method.getName();
132132
if (name.indexOf('$') == -1) {
133-
if (name.length() > 3 && name.startsWith("get")
134-
&& Character.isUpperCase(name.charAt(3))) {
133+
if (name.length() > 3 && name.startsWith("get") && (
134+
Character.isUpperCase(name.charAt(3))
135+
|| (name.length() > 4 && Character.isUpperCase(name.charAt(4)))
136+
)) {
135137
name = name.substring(3);
136138
} else if (name.length() > 2
137139
&& name.startsWith("is")

grails-core/src/test/groovy/org/grails/core/util/ClassPropertyFetcherSpec.groovy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,20 @@ class ClassPropertyFetcherSpec extends Specification {
1515
cpf.getPropertyValue(new Author(name: "Fred"),"name") == "Fred"
1616
cpf.getPropertyValue(new Author(name: "Fred", books: ["test"]),"books").contains "test"
1717
}
18+
19+
void "test properties that have the fifth letter of their getter capitalized instead of the fourth"() {
20+
when:"A class property fetcher is created"
21+
def cpf = ClassPropertyFetcher.forClass(Person)
22+
23+
then:"all properties are correct"
24+
def person = new Person(name: "Fred", xAge: 30)
25+
person.getxAge() == 30
26+
cpf.getPropertyValue(person, "xAge") == 30
27+
}
1828
}
1929
class Person {
2030
String name
31+
Integer xAge
2132
}
2233
class Author extends Person {
2334
Set books

0 commit comments

Comments
 (0)