Hi.  I just spent more time than I would have liked tracking down an
IllegalArgumentException with a useless message from
java.lang.reflect.Method.invoke().  I added some trace-level logging
to PropertyUtils (everywhere it calls a write method) and discovered
the source of my troubles right away.

I thought the logging might be useful to others, so I'm submitting it
here for your consideration in a future release.

Oh, the patch also fixes a little spelling mistake in the javadoc. :-)

-- 
Jonathan Fuerth - SQL Power Group Inc.
(416)221-4220 (Toronto); 1-866-SQL-POWR (Toll-Free)
Unleash the Power of your Corporate Data - http://www.sqlpower.ca/
--- PropertyUtils.java.1.6.1    Thu Oct  9 12:51:14 2003
+++ PropertyUtils.java  Thu Oct  9 12:53:30 2003
@@ -77,6 +77,8 @@
 import java.util.Map;
 
 import org.apache.commons.collections.FastHashMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 
 /**
@@ -142,7 +144,7 @@
 
 
     /**
-     * The delimiter that preceeds the zero-relative subscript for an
+     * The delimiter that precedes the zero-relative subscript for an
      * indexed reference.
      */
     public static final char INDEXED_DELIM = '[';
@@ -156,7 +158,7 @@
 
 
     /**
-     * The delimiter that preceeds the key of a mapped property.
+     * The delimiter that precedes the key of a mapped property.
      */
     public static final char MAPPED_DELIM = '(';
 
@@ -196,6 +198,10 @@
         debug = newDebug;
     }
 
+    /**
+     * All logging goes through this logger
+     */
+    private static Log log = LogFactory.getLog(BeanUtils.class);
 
     /**
      * The cache of PropertyDescriptor arrays for beans we have already
@@ -1432,6 +1438,15 @@
                 subscript[0] = new Integer(index);
                 subscript[1] = value;
                 try {
+                    if (log.isTraceEnabled()) {
+                        String valueClassName =
+                            value == null ? "<null>" 
+                                          : value.getClass().getName();
+                        log.trace("setSimpleProperty: Invoking method "
+                                  +writeMethod+" with index="+index
+                                  +", value="+value
+                                  +" (class "+valueClassName+")");
+                    }
                     writeMethod.invoke(bean, subscript);
                 } catch (InvocationTargetException e) {
                     if (e.getTargetException() instanceof
@@ -1580,6 +1595,14 @@
                 Object params[] = new Object[2];
                 params[0] = key;
                 params[1] = value;
+                if (log.isTraceEnabled()) {
+                    String valueClassName =
+                        value == null ? "<null>" : value.getClass().getName();
+                    log.trace("setSimpleProperty: Invoking method "
+                              +mappedWriteMethod+" with key="+key
+                              +", value="+value
+                              +" (class "+valueClassName+")");
+                }
                 mappedWriteMethod.invoke(bean, params);
             } else {
                 throw new NoSuchMethodException
@@ -1786,6 +1809,12 @@
         // Call the property setter method
         Object values[] = new Object[1];
         values[0] = value;
+        if (log.isTraceEnabled()) {
+            String valueClassName =
+                value == null ? "<null>" : value.getClass().getName();
+            log.trace("setSimpleProperty: Invoking method "+writeMethod
+                      +" with value "+value+" (class "+valueClassName+")");
+        }
         writeMethod.invoke(bean, values);
 
     }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to