FieldGroup throws NPE on optional JPA association

This is a continuation of some prior posts where I am trying to implement a real-world application with a complex data model using JPAContainer, etc.

I am working on displaying various parts of the main Entity that also shows a few of it’s association data… some of this association data itself has associated data, etc.

Some of these associations are OPTIONAL (and are annotated that way in the @OneToOne) –

However, when I try to use that type of nested property in a Form, via a FieldGroup I get an NPE at :

Caused by:$MethodException
at com.vaadin.ui.AbstractField.getDataSourceValue(
at com.vaadin.ui.AbstractField.setPropertyDataSource(
… 44 more
Caused by: java.lang.NullPointerException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(

The usage is :
ourLayout.addComponent( fieldGroup.buildAndBind( “Offense Type”, “arrestInfo.offenseTypeItem.itemText” ), 2, 8, 3, 8 );

And yes, the bean data for arrestInfo.offenseTypeItem is null – which is acceptable, it’s allowed to be null since it’s optional …

I don’t think Vaadin should throw a NPE –

What I think would be very very slick is if Vaadin accepted the ?. Groovy type annotation (arrentInfo?.offenseTypeItem?.itemText) that indicates to just return a null if any of the path is null …

But even still, I would think the logic in the NestedMethodProperty.class could just protect this too and return null …

    public T getValue() {
        try {
            Object object = instance;
            for (Method m : getMethods) {
                object = m.invoke(object);   <--- Line throwing the NPE
            return (T) object;
        } catch (final Throwable e) {
            throw new MethodException(this, e);

Something simple like:

Object object = instance; for (Method m : getMethods) { object = m.invoke(object); if ( null == object ) return (T) object ; }

Anyway – meanwhile – any ideas on how to protect this from happening cleanly? I have about 15 fields on this one form alone that have optional associations …