diff options
author | Artur Signell <artur@vaadin.com> | 2016-03-13 13:24:11 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-06-23 11:26:38 +0000 |
commit | b3ade570dbfed9cf074f333826ff5363a6db2a9c (patch) | |
tree | d8f634bf0803f2f61de76bfba4e3f7ed9eb0a28f | |
parent | 4813ce405c60445a1eb22874adc9da4e5e1a2956 (diff) | |
download | vaadin-framework-b3ade570dbfed9cf074f333826ff5363a6db2a9c.tar.gz vaadin-framework-b3ade570dbfed9cf074f333826ff5363a6db2a9c.zip |
Ensure addItem(null) returns null
Change-Id: I55d13a85d07e17a165aa6e78920c9ed3a5988f69
3 files changed, 8 insertions, 9 deletions
diff --git a/server/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java b/server/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java index 199d186fab..8590528f43 100644 --- a/server/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java +++ b/server/src/com/vaadin/data/util/ContainerHierarchicalWrapper.java @@ -538,10 +538,9 @@ public class ContainerHierarchicalWrapper implements Container.Hierarchical, */ @Override public Item addItem(Object itemId) throws UnsupportedOperationException { - // Null ids are not accepted if (itemId == null) { - throw new NullPointerException("Container item id can not be null"); + return null; } final Item item = container.addItem(itemId); diff --git a/server/src/com/vaadin/data/util/IndexedContainer.java b/server/src/com/vaadin/data/util/IndexedContainer.java index b851baf674..c00dfe8e05 100644 --- a/server/src/com/vaadin/data/util/IndexedContainer.java +++ b/server/src/com/vaadin/data/util/IndexedContainer.java @@ -269,7 +269,9 @@ public class IndexedContainer extends public Item addItem(Object itemId) { Item item = internalAddItemAtEnd(itemId, new IndexedContainerItem( itemId), false); - if (!isFiltered()) { + if (item == null) { + return null; + } else if (!isFiltered()) { // always the last item fireItemAdded(size() - 1, itemId, item); } else if (passesFilters(itemId) && !containsId(itemId)) { @@ -726,11 +728,6 @@ public class IndexedContainer extends * the Item ID of the new Item. */ private IndexedContainerItem(Object itemId) { - - // Gets the item contents from the host - if (itemId == null) { - throw new NullPointerException(); - } this.itemId = itemId; } diff --git a/server/tests/src/com/vaadin/data/util/AbstractContainerTestBase.java b/server/tests/src/com/vaadin/data/util/AbstractContainerTestBase.java index 52acc5ab76..9071f5eb40 100644 --- a/server/tests/src/com/vaadin/data/util/AbstractContainerTestBase.java +++ b/server/tests/src/com/vaadin/data/util/AbstractContainerTestBase.java @@ -211,6 +211,9 @@ public abstract class AbstractContainerTestBase extends TestCase { // Add again Item item2 = container.addItem("foo"); Assert.assertNull(item2); + + // Null is not a valid itemId + Assert.assertNull(container.addItem(null)); } catch (UnsupportedOperationException e) { // Ignore contains which do not support addItem* } @@ -526,7 +529,7 @@ public abstract class AbstractContainerTestBase extends TestCase { /** * Override in subclasses to return false if the container getItem() method * returns a non-null value for an item that has been filtered out. - * + * * @return */ protected boolean isFilteredOutItemNull() { |