Skip to content

Conversation

@iddeepak
Copy link

Summary
This PR introduces new utility methods to improve readability and reduce the risk of subtle bugs related to negated emptiness checks:

Adds CollectionUtils.isNotEmpty(Collection) Adds CollectionUtils.isNotEmpty(Map)

Motivation
As noted by @mdeinum in #35243 , negated expressions like !collection.isEmpty() can be error-prone:

public static boolean isNotEmpty(@Nullable Map<?, ? extends @Nullable Object> map) {
return (map != null && !map.isEmpty());
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mdeinum
Added isNotEmpty methods to CollectionUtils as suggested to improve readability and avoid !isEmpty() usage

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jul 28, 2025
}
String parameter = mimeType.substring(index + 1, nextIndex).trim();
if (parameter.length() > 0) {
if (StringUtils.hasLength(parameter)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use StringUtils already has a way to check
@mdeinum

@iddeepak
Copy link
Author

I see StringUtils#isEmpty is replaced with !StringUtils.hasLength everywhere, Can't we just use if string.isEmpty() ?
@mdeinum

@bclozel
Copy link
Member

bclozel commented Jul 28, 2025

Thanks for the proposal, but this has been declined multiple times, see #34519 and linked issues.

@bclozel bclozel closed this Jul 28, 2025
@bclozel bclozel added status: declined A suggestion or change that we don't feel we should currently apply and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: declined A suggestion or change that we don't feel we should currently apply

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants