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


##########
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:
   constraintsMap = [secret: [metaConstraints: [bindable: false]]] used to 
leave secret unset. hasProperty does not see a map key, so 
bindableConstraintValue returns null and secret is bound. Keep the map-key 
lookup for a map-backed constraint, and keep the metaproperty lookup for an 
ordinary constrained property.



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