alibaba/nacos · warning · IllegalArgumentException

Unsupported object type

Error message

Unsupported object type: {}

What it means

Thrown by CollectionUtils.sizeIsEmpty(Object) when the argument is a non-null object that is not a Collection, Map, Object[], Iterator, or Enumeration, and Array.getLength(object) also throws. The message appends the actual class name so you can see what was passed.

Solutions

  1. Check the class name in the error message to confirm what was passed.
  2. Convert the input to a supported type before calling (e.g., Arrays.asList for arrays, wrap in a collection).
  3. For Strings use str.isEmpty(); for primitive arrays use array.length directly.

Example fix

// before
boolean empty = CollectionUtils.sizeIsEmpty(someString);

// after
boolean empty = someString == null || someString.isEmpty();
Defensive patterns

Strategy: type-guard

Type guard

boolean isSupportedBySizeIsEmpty(Object o) {
    return o instanceof Collection || o instanceof Map
        || o instanceof Object[] || o instanceof Iterator
        || o instanceof Enumeration;
}

Try / catch

try {
    return CollectionUtils.sizeIsEmpty(obj);
} catch (IllegalArgumentException e) {
    // obj was a String, primitive array, or arbitrary POJO
    return false; // or compute size the type-specific way
}

Prevention

When it happens

Trigger: Calling sizeIsEmpty with an arbitrary object such as a String, a primitive array (int[]), a custom POJO, or any type without a measurable size.

Common situations: Passing a String (common mistake — length is queried differently); passing a primitive array like int[] (only Object[] is supported); passing a POJO where a Collection was expected.

Related errors


AI-assisted analysis of alibaba/nacos@9b989acdf1 (2026-08-14). Data as JSON: /api/errors/e1be199cb3dfdad0. Report an issue: GitHub.

Appendix: source

Thrown at common/src/main/java/com/alibaba/nacos/common/utils/CollectionUtils.java:201

     */
    public static boolean sizeIsEmpty(Object object) {
        if (object instanceof Collection) {
            return ((Collection) object).isEmpty();
        } else if (object instanceof Map) {
            return ((Map) object).isEmpty();
        } else if (object instanceof Object[]) {
            return ((Object[]) object).length == 0;
        } else if (object instanceof Iterator) {
            return ((Iterator) object).hasNext() == false;
        } else if (object instanceof Enumeration) {
            return ((Enumeration) object).hasMoreElements() == false;
        } else if (object == null) {
            throw new IllegalArgumentException("Unsupported object type: null");
        } else {
            try {
                return Array.getLength(object) == 0;
            } catch (IllegalArgumentException ex) {
                throw new IllegalArgumentException(
                    "Unsupported object type: " + object.getClass().getName());
            }
        }
    }
    
    /**
     * Whether contain item in collection.
     *
     * @param coll   collection
     * @param target target value
     * @param <T>    General Type
     * @return true if contain, otherwise false
     */
    public static <T> boolean contains(Collection<T> coll, T target) {
        if (isEmpty(coll)) {
            return false;
        }
        return coll.contains(target);

View on GitHub (pinned to 9b989acdf1)