Example usage for org.springframework.beans NullValueInNestedPathException getBeanClass

List of usage examples for org.springframework.beans NullValueInNestedPathException getBeanClass

Introduction

In this page you can find the example usage for org.springframework.beans NullValueInNestedPathException getBeanClass.

Prototype

public Class<?> getBeanClass() 

Source Link

Document

Return the offending bean class.

Usage

From source file:org.obiba.magma.beans.BeanPropertyVariableValueSource.java

@Nullable
protected Object getPropertyValue(String propertyPath, BeanWrapper bw) {
    try {/*from  ww w  .  jav  a2s  .c  o  m*/
        return bw.getPropertyValue(propertyPath);
    } catch (NullValueInNestedPathException e) {
        return null;
    } catch (InvalidPropertyException e) {
        throw new MagmaRuntimeException("Invalid definition of variable " + getVariable().getName()
                + ". Cannot obtain value for property '" + e.getPropertyName() + "' on bean of class "
                + e.getBeanClass(), e);
    }
}

From source file:org.springframework.beans.AbstractPropertyAccessorTests.java

@Test
public void getPropertyIntermediatePropertyIsNull() {
    Person target = createPerson("John", "London", "UK");
    target.address = null;/*from  w  w  w  .  j ava2  s.  co  m*/
    AbstractPropertyAccessor accessor = createAccessor(target);

    try {
        accessor.getPropertyValue("address.country.name");
        fail("Should have failed to get value with null intermediate path");
    } catch (NullValueInNestedPathException e) {
        assertEquals("address", e.getPropertyName());
        assertEquals(Person.class, e.getBeanClass());
    }
}

From source file:org.springframework.beans.AbstractPropertyAccessorTests.java

@Test
public void setPropertyIntermediatePropertyIsNull() {
    Person target = createPerson("John", "Paris", "FR");
    target.address.country = null;//  w  ww . j  a  va  2s .  c  o  m
    AbstractPropertyAccessor accessor = createAccessor(target);

    try {
        accessor.setPropertyValue("address.country.name", "UK");
        fail("Should have failed to set value with intermediate null value");
    } catch (NullValueInNestedPathException e) {
        assertEquals("address.country", e.getPropertyName());
        assertEquals(Person.class, e.getBeanClass());
    }
    assertThat(target.address.country, is(nullValue())); // Not touched
}