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
Resolve Sonarlint S1155 - Collection.isEmpty() should be used to test for emptiness
#25655
Resolve Sonarlint S1155 - Collection.isEmpty() should be used to test for emptiness
#25655
Conversation
`CollectionUtil.isEmpty()` as appropriate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In CollectionUtil we have also below method:
/**
* Returns {@code true} if the given collection is not {@code null} and not empty, otherwise returns {@code false}.
*
* @param collection the given collection
* @return {@code true} if collection is not empty
*/
public static boolean isNotEmpty(Collection collection) {
return !isEmpty(collection);
}
Is there any reason to use !CollectionUtil.isEmpty()
instead off CollectionUtil.isNotEmpty()
?
For me, second option is more clear.
Good spot, I didn't see that method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM now, thanks!
Replace checks against
.size()
with.isEmpty()
/CollectionUtil.isEmpty()
/CollectionUtil.isNotEmpty()
as appropriate