From 3a5776a90d6dd4d2d498256a09aedaa14f578bed Mon Sep 17 00:00:00 2001 From: Stefan Klotz <35995139+StefanKlt@users.noreply.github.com> Date: Tue, 2 Apr 2019 13:24:53 +0200 Subject: [PATCH] Fix cast exception in UI (#816) * check type before cast Signed-off-by: Stefan Klotz * use collection instead of set Signed-off-by: Stefan Klotz --- .../ui/common/table/AbstractTable.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java index 0fd194097..1567311d9 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/common/table/AbstractTable.java @@ -9,6 +9,7 @@ package org.eclipse.hawkbit.ui.common.table; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -131,19 +132,26 @@ public abstract class AbstractTable extends Table impleme } /** - * Gets the selected item id or in multiselect mode a set of selected ids. + * Gets the selected item id or in multiselect mode the selected ids. * * @param table * the table to retrieve the selected ID(s) * @return the ID(s) which are selected in the table */ + @SuppressWarnings("unchecked") public static Set getTableValue(final Table table) { - @SuppressWarnings("unchecked") - Set values = (Set) table.getValue(); - if (values == null) { - values = Collections.emptySet(); + final Object value = table.getValue(); + Set idsReturn; + if (value == null) { + idsReturn = Collections.emptySet(); + } else if (value instanceof Collection) { + final Collection ids = (Collection) value; + idsReturn = ids.stream().filter(Objects::nonNull).collect(Collectors.toSet()); + } else { + final T id = (T) value; + idsReturn = Collections.singleton(id); } - return values.stream().filter(Objects::nonNull).collect(Collectors.toSet()); + return idsReturn; } private void onValueChange() {