The current isEmpty method is designed to check if various types of objects are empty. However, if an unsupported object type is accidentally passed, the method simply returns false. This can cause confusion when incorrect input is provided, making it difficult to detect bugs early.

Proposal:

I propose that when an unsupported object type is passed to the isEmpty method, instead of returning false, the method should throw a clear exception (IllegalArgumentException), making it obvious that an unsupported type was provided.

public static boolean isEmpty(@Nullable Object obj) {
    ...

    // If the object type is not supported, throw an exception
    throw new IllegalArgumentException("Unsupported object type: " + obj.getClass().getName());
}

Comment From: sbrannen

Are you referring to org.springframework.util.ObjectUtils.isEmpty(Object)?

If so, that method works as designed and returns false according to its documented contract. Changing it to throw an exception would be a breaking change and therefore not an option.

In light of that, I am closing this issue.

If you are referring to some other isEmpty(Object) method in the Spring Framework and believe you have discovered a bug, please provide additional information and we will consider reopening this issue.

Cheers,

Sam