public static <T> List<T> wrap(final T source) {
        val list = new ArrayList<T>();
        if (source != null) {
            if (source instanceof final Collection values) {
                for (val value : values) {
                    list.add((T) value);
                }
            } else if (source.getClass().isArray()) {
                if (source.getClass().isAssignableFrom(byte[].class)) {
                    list.add(source);
                } else {
                    val elements = Arrays.stream((Object[]) source).toList();
                    list.addAll((Collection<? extends T>) elements);
                }
            } else {
                list.add(source);
            }
        }
        return list;
    }
Wraps a possibly null list in an immutable wrapper.

@param <T>    the type parameter
@param source list to wrap.
@return the list
core/cas-server-core-util-api/src/main/java/org/apereo/cas/util/CollectionUtils.java