commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lee Cooper (JIRA)" <j...@apache.org>
Subject [jira] Created: (BEANUTILS-367) java.lang.NullPointerException at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2168)
Date Mon, 19 Oct 2009 15:53:59 GMT
java.lang.NullPointerException at org.apache.commons.beanutils.PropertyUtilsBean.invokeMethod(PropertyUtilsBean.java:2168)
--------------------------------------------------------------------------------------------------------------------------

                 Key: BEANUTILS-367
                 URL: https://issues.apache.org/jira/browse/BEANUTILS-367
             Project: Commons BeanUtils
          Issue Type: Bug
          Components: Bean / Property Utils
    Affects Versions: 1.8.0
         Environment: 1.6 JDK
            Reporter: Lee Cooper
            Priority: Minor


the reason this is thrown is because an IllegalArgumentException is thrown and then no one
is checking the class to construct an error message anyway long story short I fixed it and
here is how I did it.... 

   private Object invokeMethod(
                        Method method, 
                        Object bean, 
                        Object[] values) 
                            throws
                                IllegalAccessException,
                                InvocationTargetException {
        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");
            }
            
            String valueString = "";
            if (values != null) {
                for (int i = 0; i < values.length; i++) {
                    if (i>0) {
                        valueString += ", " ;
                    }
                    
//
                    if(values[i] != null)
                    {
                    	valueString += (values[i]).getClass().getName();
                    }
                    else
                    {
                    	valueString += "Null Object Class Identity Not Known";
                    } 
                }
            }
            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;
            
        }
    }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message