From 9458992e79a596b4ee2eac406f9f13e0fc4fcbd5 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Fri, 14 Sep 2012 15:25:55 +0400 Subject: [PATCH] NoSuchElementException --- .../ide/util/treeView/AbstractTreeUi.java | 6 ++-- .../util/containers/ContainerUtil.java | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java index 6e0c230da31d..ff8b4b37f30a 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/AbstractTreeUi.java @@ -3834,11 +3834,11 @@ public class AbstractTreeUi { } } - Set toSelect = new THashSet(); clearSelection(); - ContainerUtil.addAll(toSelect, elements); + Set toSelect = new THashSet(); + ContainerUtil.addAllNotNull(toSelect, elements); if (addToSelection) { - toSelect.addAll(currentElements); + ContainerUtil.addAllNotNull(toSelect, currentElements); } if (checkIfInStructure) { diff --git a/platform/util/src/com/intellij/util/containers/ContainerUtil.java b/platform/util/src/com/intellij/util/containers/ContainerUtil.java index f478a58f624b..949a89880e57 100644 --- a/platform/util/src/com/intellij/util/containers/ContainerUtil.java +++ b/platform/util/src/com/intellij/util/containers/ContainerUtil.java @@ -467,6 +467,25 @@ public class ContainerUtil extends ContainerUtilRt { } } + /** + * Adds all not-null elements from the {@code elements}, ignoring nulls + */ + public static void addAllNotNull(@NotNull Collection collection, @NotNull Iterable elements) { + addAll(collection, elements.iterator()); + } + + /** + * Adds all not-null elements from the {@code elements}, ignoring nulls + */ + public static void addAllNotNull(@NotNull Collection collection, @NotNull Iterator elements) { + while (elements.hasNext()) { + T o = elements.next(); + if (o != null) { + collection.add(o); + } + } + } + @NotNull public static List collect(@NotNull Iterator iterator) { if (!iterator.hasNext()) return Collections.emptyList(); @@ -859,6 +878,19 @@ public class ContainerUtil extends ContainerUtilRt { return collection; } + /** + * Adds all not-null elements from the {@code elements}, ignoring nulls + */ + public static > C addAllNotNull(@NotNull C collection, @NotNull A... elements) { + //noinspection ManualArrayToCollectionCopy + for (T element : elements) { + if (element != null) { + collection.add(element); + } + } + return collection; + } + public static U findInstance(@NotNull Iterable iterable, @NotNull Class aClass) { return findInstance(iterable.iterator(), aClass); }