]> source.dussan.org Git - vaadin-framework.git/commitdiff
Prevent NPE in AbstractBeanContainer.getType() method (#15173).
authorDenis Anisimov <denis@vaadin.com>
Wed, 5 Nov 2014 17:37:31 +0000 (19:37 +0200)
committerVaadin Code Review <review@vaadin.com>
Mon, 1 Dec 2014 20:37:24 +0000 (20:37 +0000)
Change-Id: Ieaed329ed85c68d0da8bd169b4cc5c5886dde212

server/src/com/vaadin/data/util/AbstractBeanContainer.java
server/tests/src/com/vaadin/data/util/BeanContainerTest.java
server/tests/src/com/vaadin/data/util/BeanItemContainerTest.java

index adf63137701a706a2a6c962893cfa1cdc9850a1a..7d7d71c423b400981e7eff60f985290d41385894 100644 (file)
@@ -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();
     }
 
     /**
index 4e0e98ec43436bdc50839e0c04063a315342c958..f22ab8478e3f164d2261b62f9e8df668e54ec293 100644 (file)
@@ -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());
     }
index b58d962d960452aefdeb2f76a635c7330b236048..01c282e294d6c6999d0fd1977131468591f3e549 100644 (file)
@@ -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());
     }