Skip to content

Add Exception Handling for Unsupported Object Types in isEmpty Method #33505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dukbong opened this issue Sep 8, 2024 · 1 comment
Closed
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply

Comments

@dukbong
Copy link
Contributor

dukbong commented Sep 8, 2024

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());
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 8, 2024
@sbrannen sbrannen self-assigned this Sep 8, 2024
@sbrannen
Copy link
Member

sbrannen commented Sep 8, 2024

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

@sbrannen sbrannen closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2024
@sbrannen sbrannen added status: declined A suggestion or change that we don't feel we should currently apply in: core Issues in core modules (aop, beans, core, context, expression) and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants