hk2166 commented on code in PR #16781:
URL: https://github.com/apache/grails-core/pull/16781#discussion_r4396451912


##########
grails-web-databinding/src/main/groovy/org/grails/web/databinding/BindingIncludeLists.java:
##########
@@ -346,26 +352,43 @@ public static Map evaluateConstrainedProperties(final 
Class type) {
         return Collections.emptyMap();
     }
 
+    /**
+     * The {@code bindable} constraint of a constrained property, read from 
the property itself, from its meta
+     * constraints, or from the property it wraps.
+     * <p>
+     * Each accessor is looked up before it is called. A wrapped property, 
such as the ones a validateable class
+     * holds, has neither of the first two, and throwing and catching a 
missing method or property exception for
+     * each of them made reading the constraint cost more than the rest of a 
bind.
+     */
     public static Object bindableConstraintValue(final Object 
constrainedProperty) {
         MetaClass metaClass = 
GroovySystem.getMetaClassRegistry().getMetaClass(constrainedProperty.getClass());
         try {
-            Object value = metaClass.invokeMethod(constrainedProperty, 
"getMetaConstraintValue", new Object[] { 
DefaultASTDatabindingHelper.BINDABLE_CONSTRAINT_NAME });
-            if (value != null) {
-                return value;
+            MetaMethod metaConstraintValue = 
metaClass.getMetaMethod(META_CONSTRAINT_VALUE_ACCESSOR, 
META_CONSTRAINT_VALUE_ARGUMENT_TYPES);
+            if (metaConstraintValue != null) {
+                Object value = metaConstraintValue.invoke(constrainedProperty, 
new Object[] { DefaultASTDatabindingHelper.BINDABLE_CONSTRAINT_NAME });
+                if (value != null) {
+                    return value;
+                }
             }
         } catch (Exception ignored) {
         }
         try {
-            Object metaConstraints = 
metaClass.getProperty(constrainedProperty, "metaConstraints");
-            if (metaConstraints instanceof Map) {
-                return ((Map) 
metaConstraints).get(DefaultASTDatabindingHelper.BINDABLE_CONSTRAINT_NAME);
+            MetaProperty metaConstraintsProperty = 
metaClass.hasProperty(constrainedProperty, META_CONSTRAINTS_PROPERTY);

Review Comment:
   Good catch, fixed. `bindableConstraintValue` now reads a map-backed 
constrained property by key, for `metaConstraints` and for the `property` it 
wraps, and keeps the metaproperty lookup for everything else.
   
   Two tests in `DataBindingUtilsSpec` cover it: `constraintsMap = [secret: 
[metaConstraints: [bindable: false]]]` leaves `secret` unset, and so does a map 
that wraps a constrained property under `property`. Both pass on 8.0.x, 
reproduced your report on the previous head of this branch, and pass with the 
fix.
   



-- 
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]

Reply via email to