Copilot commented on code in PR #15947:
URL: https://github.com/apache/grails-core/pull/15947#discussion_r3553740028
##########
grails-web-databinding/src/main/groovy/grails/web/databinding/DataBindingUtils.java:
##########
@@ -119,13 +120,19 @@ public static BindingResult bindObjectToInstance(Object
object, Object source) {
}
protected static List getBindingIncludeList(final Object object) {
- List includeList = Collections.emptyList();
+ final boolean legacyBindableDefaultEnabled =
isLegacyBindableDefaultEnabled();
+ final String whiteListFieldName = legacyBindableDefaultEnabled ?
+ DefaultASTDatabindingHelper.LEGACY_DATABINDING_WHITELIST :
+ DefaultASTDatabindingHelper.DEFAULT_DATABINDING_WHITELIST;
+ final Map<Class, List> includeListCache = legacyBindableDefaultEnabled
?
+ CLASS_TO_LEGACY_BINDING_INCLUDE_LIST :
CLASS_TO_BINDING_INCLUDE_LIST;
+ List includeList = legacyBindableDefaultEnabled ?
Collections.emptyList() :
Collections.singletonList(DefaultASTDatabindingHelper.NO_BINDABLE_PROPERTIES);
try {
final Class<? extends Object> objectClass = object.getClass();
- if (CLASS_TO_BINDING_INCLUDE_LIST.containsKey(objectClass)) {
- includeList = CLASS_TO_BINDING_INCLUDE_LIST.get(objectClass);
+ if (includeListCache.containsKey(objectClass)) {
+ includeList = includeListCache.get(objectClass);
} else {
- final Field whiteListField =
objectClass.getDeclaredField(DefaultASTDatabindingHelper.DEFAULT_DATABINDING_WHITELIST);
+ final Field whiteListField =
objectClass.getDeclaredField(whiteListFieldName);
Review Comment:
`getBindingIncludeList` uses `Class.getDeclaredField(...)` to read the
injected whitelist field. Since the whitelist field is added as a **public
static** field, this lookup will fail for subclasses (for example
Hibernate/CGLIB/ByteBuddy proxy subclasses of a domain/command class). With the
new deny-by-default behavior, that failure will fall back to
`NO_BINDABLE_PROPERTIES` and bind nothing even though the superclass has the
generated allowlist.
Using `getField(...)` (or walking the superclass chain) will correctly
resolve inherited public static whitelist fields and preserve binding for
proxied instances.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]