commons-issues mailing list archives

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

     [ https://issues.apache.org/jira/browse/BEANUTILS-367?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Niall Pemberton resolved BEANUTILS-367.
---------------------------------------

    Resolution: Duplicate

This duplicates BEANUTILS-349 and will be fixed in the BeanUtils 1.8.1 release

> 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