2

The name of the variable propertyName in the PropertyPath class's constructor seems not following the JavaBeans Specification (8.8 Capitalization of inferred names.).

https://github.com/spring-projects/spring-data-commons/blob/master/src/main/java/org/springframework/data/mapping/PropertyPath.java

// PropertyPath Code: lines 73:
PropertyPath(String name, TypeInformation<?> owningType, List<PropertyPath> base) {
...
    String propertyName = name.matches(ALL_UPPERCASE) ? name : StringUtils.uncapitalize(name);
...
}

The code means the first capital letter is changed to lowercase when the name doesn't matche ALL_UPPERCASE.

But the JavaBeans Specification says:

JavaBeans Specification

Thus when we extract a property or event name from the middle of an existing Java name, 
we normally convert the first character to lower case. 
However to support the occasional use of all upper-case names, we check if the first 
two characters of the name are both upper case and if so leave it alone. 
So for example,
    “FooBah” becomes “fooBah”
    “Z” becomes “z”
    “URL” becomes “URL”

For example: If I have a property named [MCount] in a class, the property name should be [MCount] according with JavaBeans Specification. But if I use [PropertyPath.from](which will call the PropertyPath constructor) as below to get the property, I'll get the following exception, because the property name was changed to [mCount].

PropertyPath property = PropertyPath.from("MCount", classType);

Exception: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [mCount] on this ManagedType [class]...

Anyone has a good opinion? Thanks!

Lin
  • 21
  • 2

1 Answers1

2

This behavior was introduced with the commit 0c4ed8a86a in order to fix DATACMNS-257 which is only concerned with all uppercase property names.

If you consider this a bug please file it as such in the issue tracker.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
  • Thanks for your answer. But I think it's a bug. It should be concerned with first two characters only of the property names. – Lin Apr 29 '17 at 08:38