summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin
diff options
context:
space:
mode:
authorSauli Tähkäpää <sauli@vaadin.com>2014-09-26 13:41:12 +0300
committerSauli Tähkäpää <sauli@vaadin.com>2014-11-10 13:24:36 +0200
commit75378fc4b443b9e34ac4f2ce0f0fae55a37f9f66 (patch)
tree5d4d1102024907289867dddbf6aebff7a82992da /server/src/com/vaadin
parent43da5f5c83f20e0444d1505151d6c5222241ed50 (diff)
downloadvaadin-framework-75378fc4b443b9e34ac4f2ce0f0fae55a37f9f66.tar.gz
vaadin-framework-75378fc4b443b9e34ac4f2ce0f0fae55a37f9f66.zip
Add null check to FieldGroup.bind. (#14729)
Change-Id: I56ee44f34307d76c8c98ca3346feed8e7ee2f72e
Diffstat (limited to 'server/src/com/vaadin')
-rw-r--r--server/src/com/vaadin/data/fieldgroup/FieldGroup.java29
1 files changed, 22 insertions, 7 deletions
diff --git a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java
index 3a60b6912c..d84a882d80 100644
--- a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java
+++ b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java
@@ -243,15 +243,13 @@ public class FieldGroup implements Serializable {
* @param propertyId
* The propertyId to bind to the field
* @throws BindException
- * If the property id is already bound to another field by this
- * field binder
+ * If the field is null or the property id is already bound to
+ * another field by this field binder
*/
public void bind(Field<?> field, Object propertyId) throws BindException {
- if (propertyIdToField.containsKey(propertyId)
- && propertyIdToField.get(propertyId) != field) {
- throw new BindException("Property id " + propertyId
- + " is already bound to another field");
- }
+ throwIfFieldIsNull(field, propertyId);
+ throwIfPropertyIdAlreadyBound(field, propertyId);
+
fieldToPropertyId.put(field, propertyId);
propertyIdToField.put(propertyId, field);
if (itemDataSource == null) {
@@ -263,6 +261,23 @@ public class FieldGroup implements Serializable {
configureField(field);
}
+ private void throwIfFieldIsNull(Field<?> field, Object propertyId) {
+ if (field == null) {
+ throw new BindException(
+ String.format(
+ "Cannot bind property id '%s' to a null field.",
+ propertyId));
+ }
+ }
+
+ private void throwIfPropertyIdAlreadyBound(Field<?> field, Object propertyId) {
+ if (propertyIdToField.containsKey(propertyId)
+ && propertyIdToField.get(propertyId) != field) {
+ throw new BindException("Property id " + propertyId
+ + " is already bound to another field");
+ }
+ }
+
private <T> Property.Transactional<T> wrapInTransactionalProperty(
Property<T> itemProperty) {
return new TransactionalPropertyWrapper<T>(itemProperty);