Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 12084 invoked from network); 9 Oct 2003 17:37:14 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 9 Oct 2003 17:37:14 -0000 Received: (qmail 49572 invoked by uid 500); 9 Oct 2003 17:37:03 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 49399 invoked by uid 500); 9 Oct 2003 17:37:02 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 3760 invoked from network); 9 Oct 2003 17:06:11 -0000 Date: Thu, 9 Oct 2003 13:06:14 -0400 From: Jonathan Fuerth To: commons-dev@jakarta.apache.org Subject: [PATCH] beanutils - logging in PropertyUtils Message-ID: <20031009130614.B22832@fenchurch.sqlpower.ca> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="VbJkn9YxBvnuCH5J" Content-Disposition: inline User-Agent: Mutt/1.2.5i X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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/ --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="property_utils_logging.patch" --- 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 ? "" + : 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 ? "" : 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 ? "" : value.getClass().getName(); + log.trace("setSimpleProperty: Invoking method "+writeMethod + +" with value "+value+" (class "+valueClassName+")"); + } writeMethod.invoke(bean, values); } --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org --VbJkn9YxBvnuCH5J--