Author: niallp
Date: Wed Oct  7 15:23:23 2009
New Revision: 822777

URL: http://svn.apache.org/viewvc?rev=822777&view=rev
Log:
BEANUTILS-349 JDK 1.3 & 1.4 throw NullPointerException if null value for a 
primitive parameter (JDK 1.5+ throws IllegalArgumentException)

Modified:
    
commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/PropertyUtilsBean.java

Modified: 
commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/PropertyUtilsBean.java
URL: 
http://svn.apache.org/viewvc/commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/PropertyUtilsBean.java?rev=822777&r1=822776&r2=822777&view=diff
==============================================================================
--- 
commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/PropertyUtilsBean.java
 (original)
+++ 
commons/proper/beanutils/trunk/src/java/org/apache/commons/beanutils/PropertyUtilsBean.java
 Wed Oct  7 15:23:23 2009
@@ -2160,15 +2160,55 @@
                             throws
                                 IllegalAccessException,
                                 InvocationTargetException {
+        if(bean == null) {
+            throw new IllegalArgumentException("No bean specified " +
+                "- this should have been checked before reaching this method");
+        }
+
         try {
             
             return method.invoke(bean, values);
         
-        } catch (IllegalArgumentException cause) {
-            if(bean == null) {
-                throw new IllegalArgumentException("No bean specified " +
-                    "- this should have been checked before reaching this 
method");
+        } catch (NullPointerException cause) {
+            // JDK 1.3 and JDK 1.4 throw NullPointerException if an argument is
+            // null for a primitive value (JDK 1.5+ throw 
IllegalArgumentException)
+            String valueString = "";
+            if (values != null) {
+                for (int i = 0; i < values.length; i++) {
+                    if (i>0) {
+                        valueString += ", " ;
+                    }
+                    if (values[i] == null) {
+                        valueString += "<null>";
+                    } else {
+                        valueString += (values[i]).getClass().getName();
+                    }
+                }
+            }
+            String expectedString = "";
+            Class[] parTypes = method.getParameterTypes();
+            if (parTypes != null) {
+                for (int i = 0; i < parTypes.length; i++) {
+                    if (i > 0) {
+                        expectedString += ", ";
+                    }
+                    expectedString += parTypes[i].getName();
+                }
             }
+            IllegalArgumentException e = new IllegalArgumentException(
+                "Cannot invoke " + method.getDeclaringClass().getName() + "." 
+                + method.getName() + " on bean class '" + bean.getClass() +
+                "' - " + cause.getMessage()
+                // as per https://issues.apache.org/jira/browse/BEANUTILS-224
+                + " - had objects of type \"" + valueString
+                + "\" but expected signature \""
+                +   expectedString + "\""
+                );
+            if (!BeanUtils.initCause(e, cause)) {
+                log.error("Method invocation failed", cause);
+            }
+            throw e;
+        } catch (IllegalArgumentException cause) {
             String valueString = "";
             if (values != null) {
                 for (int i = 0; i < values.length; i++) {


Reply via email to