diff options
author | Denis Anisimov <denis@vaadin.com> | 2014-11-05 19:37:31 +0200 |
---|---|---|
committer | Sauli Tähkäpää <sauli@vaadin.com> | 2014-12-02 08:03:40 +0200 |
commit | 8484f25c150c068ccc3612e6059e3363eb6dc077 (patch) | |
tree | ec109b2fbc50a77e72c90824d744dbbc415b24fd | |
parent | 65754053fb92b26b1df4cafd0605e6c2546f204e (diff) | |
download | vaadin-framework-8484f25c150c068ccc3612e6059e3363eb6dc077.tar.gz vaadin-framework-8484f25c150c068ccc3612e6059e3363eb6dc077.zip |
Prevent NPE in AbstractBeanContainer.getType() method (#15173).
Change-Id: Ieaed329ed85c68d0da8bd169b4cc5c5886dde212
3 files changed, 32 insertions, 2 deletions
diff --git a/server/src/com/vaadin/data/util/AbstractBeanContainer.java b/server/src/com/vaadin/data/util/AbstractBeanContainer.java index adf6313770..7d7d71c423 100644 --- a/server/src/com/vaadin/data/util/AbstractBeanContainer.java +++ b/server/src/com/vaadin/data/util/AbstractBeanContainer.java @@ -152,7 +152,7 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends * A description of the properties found in beans of type {@link #type}. * Determines the property ids that are present in the container. */ - private LinkedHashMap<String, VaadinPropertyDescriptor<BEANTYPE>> model; + private final LinkedHashMap<String, VaadinPropertyDescriptor<BEANTYPE>> model; /** * Constructs a {@code AbstractBeanContainer} for beans of the given type. @@ -178,7 +178,11 @@ public abstract class AbstractBeanContainer<IDTYPE, BEANTYPE> extends */ @Override public Class<?> getType(Object propertyId) { - return model.get(propertyId).getPropertyType(); + VaadinPropertyDescriptor<BEANTYPE> descriptor = model.get(propertyId); + if (descriptor == null) { + return null; + } + return descriptor.getPropertyType(); } /** diff --git a/server/tests/src/com/vaadin/data/util/BeanContainerTest.java b/server/tests/src/com/vaadin/data/util/BeanContainerTest.java index 4e0e98ec43..f22ab8478e 100644 --- a/server/tests/src/com/vaadin/data/util/BeanContainerTest.java +++ b/server/tests/src/com/vaadin/data/util/BeanContainerTest.java @@ -68,6 +68,19 @@ public class BeanContainerTest extends AbstractBeanContainerTest { return false; } + public void testGetType_existingProperty_typeReturned() { + BeanContainer<String, ClassName> container = getContainer(); + Assert.assertEquals( + "Unexpected type is returned for property 'simpleName'", + String.class, container.getType("simpleName")); + } + + public void testGetType_notExistingProperty_nullReturned() { + BeanContainer<String, ClassName> container = getContainer(); + Assert.assertNull("Not null type is returned for property ''", + container.getType("")); + } + public void testBasicOperations() { testBasicContainerOperations(getContainer()); } diff --git a/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java b/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java index b58d962d96..01c282e294 100644 --- a/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java +++ b/server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java @@ -71,6 +71,19 @@ public class BeanItemContainerTest extends AbstractBeanContainerTest { return false; } + public void testGetType_existingProperty_typeReturned() { + BeanItemContainer<ClassName> container = getContainer(); + Assert.assertEquals( + "Unexpected type is returned for property 'simpleName'", + String.class, container.getType("simpleName")); + } + + public void testGetType_notExistingProperty_nullReturned() { + BeanItemContainer<ClassName> container = getContainer(); + Assert.assertNull("Not null type is returned for property ''", + container.getType("")); + } + public void testBasicOperations() { testBasicContainerOperations(getContainer()); } |