From f6b9f60a004645326ccab4ed5b65a6c7e7ef0d32 Mon Sep 17 00:00:00 2001 From: Sauli Tähkäpää Date: Fri, 26 Sep 2014 13:41:12 +0300 Subject: Add null check to FieldGroup.bind. (#14729) Change-Id: I56ee44f34307d76c8c98ca3346feed8e7ee2f72e --- .../src/com/vaadin/data/fieldgroup/FieldGroup.java | 29 ++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'server/src/com') diff --git a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java index 6f3a67a92a..5a4e877554 100644 --- a/server/src/com/vaadin/data/fieldgroup/FieldGroup.java +++ b/server/src/com/vaadin/data/fieldgroup/FieldGroup.java @@ -245,15 +245,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) { @@ -265,6 +263,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 Property.Transactional wrapInTransactionalProperty( Property itemProperty) { return new TransactionalPropertyWrapper(itemProperty); -- cgit v1.2.3