commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r410326 - in /jakarta/commons/proper/validator/trunk: src/share/org/apache/commons/validator/Field.java xdocs/changes.xml
Date Tue, 30 May 2006 17:41:51 GMT
Author: niallp
Date: Tue May 30 10:41:51 2006
New Revision: 410326

URL: http://svn.apache.org/viewvc?rev=410326&view=rev
Log:
Fix for VALIDATOR-189 - Validating indexed properties fails when null - thanks to Thomas Bailey

Modified:
    jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/Field.java
    jakarta/commons/proper/validator/trunk/xdocs/changes.xml

Modified: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/Field.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/Field.java?rev=410326&r1=410325&r2=410326&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/Field.java
(original)
+++ jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/Field.java
Tue May 30 10:41:51 2006
@@ -740,6 +740,39 @@
         }
 
     }
+    /**
+     * Returns the size of an indexed property from the object we're validating.
+     *
+     * @param bean The bean to extract the indexed values from.
+     * @throws ValidatorException If there's an error looking up the property 
+     * or, the property found is not indexed.
+     */
+    private int getIndexedPropertySize(Object bean) throws ValidatorException {
+        Object indexedProperty = null;
+
+        try {
+            indexedProperty =
+                PropertyUtils.getProperty(bean, this.getIndexedListProperty());
+
+        } catch(IllegalAccessException e) {
+            throw new ValidatorException(e.getMessage());
+        } catch(InvocationTargetException e) {
+            throw new ValidatorException(e.getMessage());
+        } catch(NoSuchMethodException e) {
+            throw new ValidatorException(e.getMessage());
+        }
+
+        if (indexedProperty == null) {
+            return 0;
+        } else if (indexedProperty instanceof Collection) {
+            return ((Collection)indexedProperty).size();
+        } else if (indexedProperty.getClass().isArray()) {
+            return ((Object[])indexedProperty).length;
+        } else {
+            throw new ValidatorException(this.getKey() + " is not indexed");
+        }
+
+    }
     
     /**
      * Executes the given ValidatorAction and all ValidatorActions that it 
@@ -829,7 +862,7 @@
 
         Object bean = params.get(Validator.BEAN_PARAM);
         int numberOfFieldsToValidate =
-            this.isIndexed() ? this.getIndexedProperty(bean).length : 1;
+            this.isIndexed() ? this.getIndexedPropertySize(bean) : 1;
 
         for (int fieldNumber = 0; fieldNumber < numberOfFieldsToValidate; fieldNumber++)
{
             

Modified: jakarta/commons/proper/validator/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/xdocs/changes.xml?rev=410326&r1=410325&r2=410326&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/validator/trunk/xdocs/changes.xml Tue May 30 10:41:51 2006
@@ -39,6 +39,9 @@
   <body>
 
     <release version="1.3.1" date="Pending">
+      <action dev="niallp" type="fix" issue="VALIDATOR-189" due-to="Thomas Bailey">
+        Validating indexed properties fails when <code>null</code>.
+      </action>
       <action dev="martinc" type="fix" issue="VALIDATOR-89" due-to="Takayuki Kaneko">
         Fix a thread safety issue in parameter initialization.
       </action>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message