Aaron Long
2014-01-06 22:00:57 UTC
After upgrading to Grails 2.3.4, I've noticed that my non-persistent
properties on objects are being called on save() (things with just getters,
for instance).
Digging around, I see this method:
/**
* Refreshes the object from entity state.
*/
public void refresh() {
final PropertyDescriptor[] descriptors =
beanWrapper.getPropertyDescriptors();
for (PropertyDescriptor descriptor : descriptors) {
final String name = descriptor.getName();
if (EXCLUDED_PROPERTIES.contains(name)) {
continue;
}
if (!beanWrapper.isReadableProperty(name) ||
!beanWrapper.isWritableProperty(name)) {
continue;
}
Object newValue = getProperty(name);
setProperty(name, newValue);
}
}
One of the descriptors in this loop is the property "properties", which is
a DataBindingLazyMetaPropertyMap containing ALL properties, even
non-writable ones. It ends up going through some of the converters and
calling all those getters, even though the refresh() seems to want to avoid
anything that isn't both writable and readable.
Not sure what changed in 2.3 to make this behavior start but it seems like
"properties" should be added to the EXCLUDED_PROPERTIES map.
I'm glad to open a JIRA and submit a patch, just wanted to make sure I
wasn't missing anything...
-Aaron
properties on objects are being called on save() (things with just getters,
for instance).
Digging around, I see this method:
/**
* Refreshes the object from entity state.
*/
public void refresh() {
final PropertyDescriptor[] descriptors =
beanWrapper.getPropertyDescriptors();
for (PropertyDescriptor descriptor : descriptors) {
final String name = descriptor.getName();
if (EXCLUDED_PROPERTIES.contains(name)) {
continue;
}
if (!beanWrapper.isReadableProperty(name) ||
!beanWrapper.isWritableProperty(name)) {
continue;
}
Object newValue = getProperty(name);
setProperty(name, newValue);
}
}
One of the descriptors in this loop is the property "properties", which is
a DataBindingLazyMetaPropertyMap containing ALL properties, even
non-writable ones. It ends up going through some of the converters and
calling all those getters, even though the refresh() seems to want to avoid
anything that isn't both writable and readable.
Not sure what changed in 2.3 to make this behavior start but it seems like
"properties" should be added to the EXCLUDED_PROPERTIES map.
I'm glad to open a JIRA and submit a patch, just wanted to make sure I
wasn't missing anything...
-Aaron