r225 - trunk/cantharella.utils/src/main/java/nc/ird/cantharella/utils
Author: echatellier Date: 2013-05-23 14:24:45 +0200 (Thu, 23 May 2013) New Revision: 225 Url: http://forge.codelutin.com/projects/cantharella/repository/revisions/225 Log: Fix NPE when sort property become null Modified: trunk/cantharella.utils/src/main/java/nc/ird/cantharella/utils/BeanTools.java Modified: trunk/cantharella.utils/src/main/java/nc/ird/cantharella/utils/BeanTools.java =================================================================== --- trunk/cantharella.utils/src/main/java/nc/ird/cantharella/utils/BeanTools.java 2013-05-21 12:36:43 UTC (rev 224) +++ trunk/cantharella.utils/src/main/java/nc/ird/cantharella/utils/BeanTools.java 2013-05-23 12:24:45 UTC (rev 225) @@ -25,6 +25,7 @@ import java.beans.PropertyDescriptor; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; @@ -61,9 +62,6 @@ /** Error message for field not found in a class */ private static final String FIELD = "Argument of type %s must have an accessible %s property"; - /** Parameters */ - private static final Object[] PARAMETERS = new Object[0]; - /** * Equals method * @param thiz First object ("this", not null) @@ -309,8 +307,9 @@ switch (accessType) { case GETTER: try { - value = new PropertyDescriptor(property, bean.getClass(), "is" + StringUtils.capitalize(property), null) - .getReadMethod().invoke(bean, PARAMETERS); + PropertyDescriptor prodDesc = new PropertyDescriptor(property, bean.getClass(), "is" + StringUtils.capitalize(property), null); + Method method = prodDesc.getReadMethod(); + value = method.invoke(bean); } catch (RuntimeException e) { throw e; } catch (Exception e) { @@ -346,7 +345,9 @@ List<String> beanNames = createAccessBeanList(pathToProperty); Object curBean = bean; for (String beanName : beanNames) { - curBean = BeanTools.getValue(curBean, AccessType.GETTER, beanName); + if (curBean != null) { + curBean = BeanTools.getValue(curBean, AccessType.GETTER, beanName); + } } return curBean; }
participants (1)
-
echatellier@users.forge.codelutin.com