summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-11-29 11:53:20 +0200
committerVaadin Code Review <review@vaadin.com>2013-11-30 07:32:25 +0000
commit8d6256e98a63222f4b4969612d8d777a31974613 (patch)
tree05a7b9435e793e421c5eed7849ec0d6eab414998 /server/src/com/vaadin
parentde1c343ea9079f74276484c7d5f1623b5391eaba (diff)
downloadvaadin-framework-8d6256e98a63222f4b4969612d8d777a31974613.tar.gz
vaadin-framework-8d6256e98a63222f4b4969612d8d777a31974613.zip
Simplified support for null intermediate properties (#11435)
Removed support for explicitly throwing NPE for intermediate properties as no use case could be identified where this would be the expected or wanted behavior. Change-Id: I10696467f792e234326075bbcdd5aad487905a7e
Diffstat (limited to 'server/src/com/vaadin')
-rw-r--r--server/src/com/vaadin/data/util/AbstractBeanContainer.java67
-rw-r--r--server/src/com/vaadin/data/util/BeanItem.java30
-rw-r--r--server/src/com/vaadin/data/util/NestedMethodProperty.java63
-rw-r--r--server/src/com/vaadin/data/util/NestedPropertyDescriptor.java24
4 files changed, 21 insertions, 163 deletions
diff --git a/server/src/com/vaadin/data/util/AbstractBeanContainer.java b/server/src/com/vaadin/data/util/AbstractBeanContainer.java
index 67239996a2..d94588bdc9 100644
--- a/server/src/com/vaadin/data/util/AbstractBeanContainer.java
+++ b/server/src/com/vaadin/data/util/AbstractBeanContainer.java
@@ -848,8 +848,9 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends
* Adds a nested container property for the container, e.g.
* "manager.address.street".
*
- * All intermediate getters must exist and must return non-null values when
- * the property value is accessed.
+ * All intermediate getters must exist and should return non-null values
+ * when the property value is accessed. If an intermediate getter returns
+ * null, a null value will be returned.
*
* @see NestedMethodProperty
*
@@ -857,32 +858,8 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends
* @return true if the property was added
*/
public boolean addNestedContainerProperty(String propertyId) {
- return addNestedContainerProperty(propertyId, false);
- }
-
- /**
- * Adds a nested container property for the container, e.g.
- * "manager.address.street".
- *
- * All intermediate getters must exist and must return non-null values when
- * the property value is accessed or the <code>nullBeansAllowed</code> must
- * be set to true. If the <code>nullBeansAllowed</code> flag is set to true,
- * calling getValue of the added property will return null if the property
- * or any of its intermediate getters returns null. If set to false, null
- * values returned by intermediate getters will cause NullPointerException.
- * The default value is false to ensure backwards compatibility.
- *
- * @see NestedMethodProperty
- *
- * @param propertyId
- * @param nullBeansAllowed
- * set true to allow null values from intermediate getters
- * @return true if the property was added
- */
- public boolean addNestedContainerProperty(String propertyId,
- boolean nullBeansAllowed) {
return addContainerProperty(propertyId, new NestedPropertyDescriptor(
- propertyId, type, nullBeansAllowed));
+ propertyId, type));
}
/**
@@ -890,8 +867,9 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends
* property to the container. The named property itself is removed from the
* model as its subproperties are added.
*
- * All intermediate getters must exist and must return non-null values when
- * the property value is accessed.
+ * All intermediate getters must exist and should return non-null values
+ * when the property value is accessed. If an intermediate getter returns
+ * null, a null value will be returned.
*
* @see NestedMethodProperty
* @see #addNestedContainerProperty(String)
@@ -900,42 +878,13 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends
*/
@SuppressWarnings("unchecked")
public void addNestedContainerBean(String propertyId) {
- addNestedContainerBean(propertyId, false);
- }
-
- /**
- * Adds a nested container properties for all sub-properties of a named
- * property to the container. The named property itself is removed from the
- * model as its subproperties are added.
- *
- * Unless
- * <code>nullBeansAllowed<code> is set to true, all intermediate getters must
- * exist and must return non-null values when the property values are
- * accessed. If the <code>nullBeansAllowed</code> flag is set to true,
- * calling getValue of the added subproperties will return null if the
- * property or any of their intermediate getters returns null. If set to
- * false, null values returned by intermediate getters will cause
- * NullPointerException. The default value is false to ensure backwards
- * compatibility.
- *
- * @see NestedMethodProperty
- * @see #addNestedContainerProperty(String)
- *
- * @param propertyId
- * @param nullBeansAllowed
- * set true to allow null values from intermediate getters
- */
- @SuppressWarnings("unchecked")
- public void addNestedContainerBean(String propertyId,
- boolean nullBeansAllowed) {
Class<?> propertyType = getType(propertyId);
LinkedHashMap<String, VaadinPropertyDescriptor<Object>> pds = BeanItem
.getPropertyDescriptors((Class<Object>) propertyType);
for (String subPropertyId : pds.keySet()) {
String qualifiedPropertyId = propertyId + "." + subPropertyId;
NestedPropertyDescriptor<BEANTYPE> pd = new NestedPropertyDescriptor<BEANTYPE>(
- qualifiedPropertyId, (Class<BEANTYPE>) type,
- nullBeansAllowed);
+ qualifiedPropertyId, (Class<BEANTYPE>) type);
model.put(qualifiedPropertyId, pd);
model.remove(propertyId);
for (BeanItem<BEANTYPE> item : itemIdToItem.values()) {
diff --git a/server/src/com/vaadin/data/util/BeanItem.java b/server/src/com/vaadin/data/util/BeanItem.java
index 4834fe4f89..49f5f95898 100644
--- a/server/src/com/vaadin/data/util/BeanItem.java
+++ b/server/src/com/vaadin/data/util/BeanItem.java
@@ -255,12 +255,13 @@ public class BeanItem<BT> extends PropertysetItem {
}
/**
- * Adds a nested property to the item.
+ * Adds a nested property to the item. The property must not exist in the
+ * item already and must of form "field1.field2" where field2 is a field in
+ * the object referenced to by field1. If an intermediate property returns
+ * null, the property will return a null value
*
* @param nestedPropertyId
- * property id to add. This property must not exist in the item
- * already and must of of form "field1.field2" where field2 is a
- * field in the object referenced to by field1
+ * property id to add.
*/
public void addNestedProperty(String nestedPropertyId) {
addItemProperty(nestedPropertyId, new NestedMethodProperty<Object>(
@@ -268,27 +269,6 @@ public class BeanItem<BT> extends PropertysetItem {
}
/**
- * Adds a nested property to the item. If the <code>nullBeansAllowed</code>
- * flag is set to true, calling getValue of the added property will return
- * null if the property or any of its intermediate getters returns null. If
- * set to false, null values returned by intermediate getters will cause
- * NullPointerException. The default value is false to ensure backwards
- * compatibility.
- *
- * @param nestedPropertyId
- * property id to add. This property must not exist in the item
- * already and must of of form "field1.field2" where field2 is a
- * field in the object referenced to by field1
- * @param nullBeansAllowed
- * set true to allow null values from intermediate getters
- */
- public void addNestedProperty(String nestedPropertyId,
- boolean nullBeansAllowed) {
- addItemProperty(nestedPropertyId, new NestedMethodProperty<Object>(
- getBean(), nestedPropertyId, nullBeansAllowed));
- }
-
- /**
* Gets the underlying JavaBean object.
*
* @return the bean object.
diff --git a/server/src/com/vaadin/data/util/NestedMethodProperty.java b/server/src/com/vaadin/data/util/NestedMethodProperty.java
index 7a3963c17e..8fe3b9d4c5 100644
--- a/server/src/com/vaadin/data/util/NestedMethodProperty.java
+++ b/server/src/com/vaadin/data/util/NestedMethodProperty.java
@@ -31,8 +31,9 @@ import com.vaadin.data.util.MethodProperty.MethodException;
* The property is specified in the dotted notation, e.g. "address.street", and
* can contain multiple levels of nesting.
*
- * When accessing the property value, all intermediate getters must return
- * non-null values or the <code>nullBeansAllowed</code> must be set to true.
+ * When accessing the property value, all intermediate getters must exist and
+ * should return non-null values when the property value is accessed. If an
+ * intermediate getter returns null, a null value will be returned.
*
* @see MethodProperty
*
@@ -55,15 +56,6 @@ public class NestedMethodProperty<T> extends AbstractProperty<T> {
*/
private Object instance;
- /**
- * a boolean flag indicating whether intermediate getters may return null
- * values. If the flag is set to true, calling getValue will return null if
- * the property or any of its intermediate getters returns null. If set to
- * false, intermediate getters returning null value will throw Exception.
- * The default value is false to ensure backwards compatibility.
- */
- private boolean nullBeansAllowed = false;
-
private Class<? extends T> type;
/* Special serialization to handle method references */
@@ -85,6 +77,8 @@ public class NestedMethodProperty<T> extends AbstractProperty<T> {
* Constructs a nested method property for a given object instance. The
* property name is a dot separated string pointing to a nested property,
* e.g. "manager.address.street".
+ * <p>
+ * Calling getValue will return null if any intermediate getter returns null
*
* @param instance
* top-level bean to which the property applies
@@ -94,33 +88,7 @@ public class NestedMethodProperty<T> extends AbstractProperty<T> {
* if the property name is invalid
*/
public NestedMethodProperty(Object instance, String propertyName) {
- this(instance, propertyName, false);
- }
-
- /**
- * Constructs a nested method property for a given object instance. The
- * property name is a dot separated string pointing to a nested property,
- * e.g. "manager.address.street". The <code>nullBeansAllowed</code> controls
- * the behavior in cases where the intermediate getters may return null
- * values. If the flag is set to true, calling getValue will return null if
- * the property or any of its intermediate getters returns null. If set to
- * false, null values returned by intermediate getters will cause
- * NullPointerException. The default value is false to ensure backwards
- * compatibility.
- *
- * @param instance
- * top-level bean to which the property applies
- * @param propertyName
- * dot separated nested property name
- * @param nullBeansAllowed
- * set true to allow null values from intermediate getters
- * @throws IllegalArgumentException
- * if the property name is invalid
- */
- public NestedMethodProperty(Object instance, String propertyName,
- boolean nullBeansAllowed) {
this.instance = instance;
- this.nullBeansAllowed = nullBeansAllowed;
initialize(instance.getClass(), propertyName);
}
@@ -139,25 +107,6 @@ public class NestedMethodProperty<T> extends AbstractProperty<T> {
}
/**
- * For internal use to deduce property type etc. without a bean instance.
- * Calling {@link #setValue(Object)} or {@link #getValue()} on properties
- * constructed this way is not supported.
- *
- * @param instanceClass
- * class of the top-level bean
- * @param propertyName
- * dot separated nested property name
- * @param nullBeansAllowed
- * set true to allow null values from intermediate getters
- */
- NestedMethodProperty(Class<?> instanceClass, String propertyName,
- boolean nullBeansAllowed) {
- instance = null;
- this.nullBeansAllowed = nullBeansAllowed;
- initialize(instanceClass, propertyName);
- }
-
- /**
* Initializes most of the internal fields based on the top-level bean
* instance and property name (dot-separated string).
*
@@ -253,7 +202,7 @@ public class NestedMethodProperty<T> extends AbstractProperty<T> {
Object object = instance;
for (Method m : getMethods) {
object = m.invoke(object);
- if (object == null && nullBeansAllowed) {
+ if (object == null) {
return null;
}
}
diff --git a/server/src/com/vaadin/data/util/NestedPropertyDescriptor.java b/server/src/com/vaadin/data/util/NestedPropertyDescriptor.java
index 67eb30fae5..b2055fe776 100644
--- a/server/src/com/vaadin/data/util/NestedPropertyDescriptor.java
+++ b/server/src/com/vaadin/data/util/NestedPropertyDescriptor.java
@@ -34,7 +34,6 @@ public class NestedPropertyDescriptor<BT> implements
private final String name;
private final Class<?> propertyType;
- private final boolean nullBeansAllowed;
/**
* Creates a property descriptor that can create MethodProperty instances to
@@ -49,29 +48,10 @@ public class NestedPropertyDescriptor<BT> implements
*/
public NestedPropertyDescriptor(String name, Class<BT> beanType)
throws IllegalArgumentException {
- this(name, beanType, false);
- }
-
- /**
- * Creates a property descriptor that can create MethodProperty instances to
- * access the underlying bean property.
- *
- * @param name
- * of the property in a dotted path format, e.g. "address.street"
- * @param beanType
- * type (class) of the top-level bean
- * @param nullBeansAllowed
- * set true to allow null values from intermediate getters
- * @throws IllegalArgumentException
- * if the property name is invalid
- */
- public NestedPropertyDescriptor(String name, Class<BT> beanType,
- boolean nullBeansAllowed) throws IllegalArgumentException {
this.name = name;
NestedMethodProperty<?> property = new NestedMethodProperty<Object>(
- beanType, name, nullBeansAllowed);
+ beanType, name);
this.propertyType = property.getType();
- this.nullBeansAllowed = nullBeansAllowed;
}
@Override
@@ -86,7 +66,7 @@ public class NestedPropertyDescriptor<BT> implements
@Override
public Property<?> createProperty(BT bean) {
- return new NestedMethodProperty<Object>(bean, name, nullBeansAllowed);
+ return new NestedMethodProperty<Object>(bean, name);
}
}