Skip to content
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

Conversation

JackPGreen
Copy link
Contributor

@JackPGreen JackPGreen commented Oct 9, 2023

Replace checks against .size() with .isEmpty() / CollectionUtil.isEmpty() / CollectionUtil.isNotEmpty() as appropriate

`CollectionUtil.isEmpty()` as appropriate
@JackPGreen JackPGreen added Team: Core Type: Cleanup Source: Internal PR or issue was opened by an employee labels Oct 9, 2023
@JackPGreen JackPGreen added this to the 5.4 Backlog milestone Oct 9, 2023
@JackPGreen JackPGreen requested a review from a team as a code owner October 9, 2023 19:29
@JackPGreen JackPGreen self-assigned this Oct 9, 2023
Copy link
Contributor

@Patras3 Patras3 left a 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.

@JackPGreen
Copy link
Contributor Author

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.

fcdb3cf

Copy link
Contributor

@Patras3 Patras3 left a comment

Choose a reason for hiding this comment

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

LGTM now, thanks!

@JackPGreen JackPGreen merged commit 185c94b into hazelcast:master Oct 10, 2023
6 of 8 checks passed
@JackPGreen JackPGreen deleted the Collection.isEmpty()_should_be_used_to_test_for_emptiness branch October 10, 2023 17:06
@AyberkSorgun AyberkSorgun modified the milestones: 5.4 Backlog, 5.4.0 Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants