From cec9c6bdcffde03fbfd69b3a1872e4399fc28213 Mon Sep 17 00:00:00 2001 From: Joonas Lehtinen Date: Wed, 14 May 2008 13:05:14 +0000 Subject: [PATCH] Fixes #1373 svn changeset:4483/svn branch:trunk --- src/com/itmill/toolkit/data/Container.java | 1 + src/com/itmill/toolkit/data/Item.java | 2 +- .../data/util/ContainerHierarchicalWrapper.java | 3 +++ src/com/itmill/toolkit/data/util/IndexedContainer.java | 10 +++++++++- src/com/itmill/toolkit/data/util/PropertysetItem.java | 3 +++ 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/com/itmill/toolkit/data/Container.java b/src/com/itmill/toolkit/data/Container.java index 46cedf8e25..80fe984c14 100644 --- a/src/com/itmill/toolkit/data/Container.java +++ b/src/com/itmill/toolkit/data/Container.java @@ -19,6 +19,7 @@ import java.util.Collection; * {@link Item#getItemPropertyIds()}). *
  • all Properties in the Items corresponding to the same Property ID must * have the same data type. + *
  • All Items within a container are uniquely identified by their non-null ids * * *

    diff --git a/src/com/itmill/toolkit/data/Item.java b/src/com/itmill/toolkit/data/Item.java index 4645dbae98..21964d29b4 100644 --- a/src/com/itmill/toolkit/data/Item.java +++ b/src/com/itmill/toolkit/data/Item.java @@ -9,7 +9,7 @@ import java.util.Collection; /** *

    * Provides a mechanism for handling a set of Properties, each associated to a - * locally unique identifier. The interface is split into subinterfaces to + * locally unique non-null identifier. The interface is split into subinterfaces to * enable a class to implement only the functionalities it needs. *

    * diff --git a/src/com/itmill/toolkit/data/util/ContainerHierarchicalWrapper.java b/src/com/itmill/toolkit/data/util/ContainerHierarchicalWrapper.java index 136bd7318b..f4ea5b5a56 100644 --- a/src/com/itmill/toolkit/data/util/ContainerHierarchicalWrapper.java +++ b/src/com/itmill/toolkit/data/util/ContainerHierarchicalWrapper.java @@ -439,6 +439,9 @@ public class ContainerHierarchicalWrapper implements Container.Hierarchical, */ 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"); + final Item item = container.addItem(itemId); if (!hierarchical && item != null) { addToHierarchyWrapper(itemId); diff --git a/src/com/itmill/toolkit/data/util/IndexedContainer.java b/src/com/itmill/toolkit/data/util/IndexedContainer.java index 002cbde970..ea8a01756a 100644 --- a/src/com/itmill/toolkit/data/util/IndexedContainer.java +++ b/src/com/itmill/toolkit/data/util/IndexedContainer.java @@ -140,6 +140,10 @@ public class IndexedContainer implements Container, Container.Indexed, * not found in the list */ public Item getItem(Object itemId) { + + // Null ids are not accepted + if (itemId == null) throw new NullPointerException("Container item id can not be null"); + if (items.containsKey(itemId) && (filteredItemIds == null || filteredItemIds.contains(itemId))) { return new IndexedContainerItem(itemId); @@ -335,6 +339,9 @@ public class IndexedContainer implements Container, Container.Indexed, */ public Item addItem(Object itemId) { + // Null ids are not accepted + if (itemId == null) throw new NullPointerException("Container item id can not be null"); + // Makes sure that the Item has not been created yet if (items.containsKey(itemId)) { return null; @@ -1188,7 +1195,8 @@ public class IndexedContainer implements Container, Container.Indexed, */ private IndexedContainerProperty(Object itemId, Object propertyId) { if (itemId == null || propertyId == null) { - throw new NullPointerException(); + // Null ids are not accepted + throw new NullPointerException("Container item or property ids can not be null"); } this.propertyId = propertyId; this.itemId = itemId; diff --git a/src/com/itmill/toolkit/data/util/PropertysetItem.java b/src/com/itmill/toolkit/data/util/PropertysetItem.java index 457a51321f..b191520a0f 100644 --- a/src/com/itmill/toolkit/data/util/PropertysetItem.java +++ b/src/com/itmill/toolkit/data/util/PropertysetItem.java @@ -108,6 +108,9 @@ public class PropertysetItem implements Item, Item.PropertySetChangeNotifier, */ public boolean addItemProperty(Object id, Property property) { + // Null ids are not accepted + if (id == null) throw new NullPointerException("Item property id can not be null"); + // Cant add a property twice if (map.containsKey(id)) { return false; -- 2.39.5