How to prevent NPE when accessing a nested/indexed property of a bean

Posted by Mohsen on Stack Overflow See other posts from Stack Overflow or by Mohsen
Published on 2010-05-02T10:57:54Z Indexed on 2010/05/02 11:08 UTC
Read the original article Hit count: 342

Is there any way to prevent NPE when accessing a nested bean using commons-beanutils? Here is my code:

new BeanUtilsBean().getProperty(human, "parent.name");

In this case I want getProperty() to either return empty string ("") when human.getParent() == null or handle it in a way other that throwing an NPE.

© Stack Overflow or respective owner

Related posts about java

Related posts about commons-beanutils