diff options
author | Artur Signell <artur@vaadin.com> | 2016-03-13 13:24:11 +0200 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2016-05-03 09:35:29 +0300 |
commit | d1bd111c4effde09d3457606866ef4d6ea92b7dd (patch) | |
tree | 0e21b1deedf0b82ae0487d77ff285c783955045c /server | |
parent | e46f20f803dc1d4d30d88b8f891dd0da6a221e1c (diff) | |
download | vaadin-framework-d1bd111c4effde09d3457606866ef4d6ea92b7dd.tar.gz vaadin-framework-d1bd111c4effde09d3457606866ef4d6ea92b7dd.zip |
Ensure addItem(null) returns null
Change-Id: I67823b306e68637b469ed35fad00f6af64e8cc15
Diffstat (limited to 'server')
3 files changed, 8 insertions, 9 deletions
diff --git a/server/src/main/java/com/vaadin/data/util/ContainerHierarchicalWrapper.java b/server/src/main/java/com/vaadin/data/util/ContainerHierarchicalWrapper.java index 199d186fab..8590528f43 100644 --- a/server/src/main/java/com/vaadin/data/util/ContainerHierarchicalWrapper.java +++ b/server/src/main/java/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/main/java/com/vaadin/data/util/IndexedContainer.java b/server/src/main/java/com/vaadin/data/util/IndexedContainer.java index 8783c061ac..c281fb35c1 100644 --- a/server/src/main/java/com/vaadin/data/util/IndexedContainer.java +++ b/server/src/main/java/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/src/test/java/com/vaadin/data/util/AbstractContainerTestBase.java b/server/src/test/java/com/vaadin/data/util/AbstractContainerTestBase.java index 64f1a31399..138beb7f3d 100644 --- a/server/src/test/java/com/vaadin/data/util/AbstractContainerTestBase.java +++ b/server/src/test/java/com/vaadin/data/util/AbstractContainerTestBase.java @@ -219,6 +219,9 @@ public abstract class AbstractContainerTestBase { // 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* } @@ -534,7 +537,7 @@ public abstract class AbstractContainerTestBase { /** * 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() { |