Skip to content

Comments

Fix sonar issue s1155 'Collection.isEmpty()' should be used to test for emptiness#83

Open
jlerbsc wants to merge 1 commit intoyuu-nkjm:masterfrom
jlerbsc:s1155
Open

Fix sonar issue s1155 'Collection.isEmpty()' should be used to test for emptiness#83
jlerbsc wants to merge 1 commit intoyuu-nkjm:masterfrom
jlerbsc:s1155

Conversation

@jlerbsc
Copy link

@jlerbsc jlerbsc commented Apr 6, 2025

We propose the fix to violation s1155 "Collection.isEmpty() should be used to test for emptiness" identified by SonarQube.

When you call isEmpty(), it clearly communicates the code’s intention, which is to check if the collection is empty. Using size() == 0 for this purpose is less direct and makes the code slightly more complex.
Moreover, depending on the implementation, the size() method can have a time complexity of O(n) where n is the number of elements in the collection. On the other hand, isEmpty() simply checks if there is at least one element in the collection, which is a constant time operation, O(1).

This patch has been automatically produced by our java code remediation solution, available free of charge for all open source projects (https://www.indepth.fr/).

We believe that this PR can improve the quality of your project code to a certain extent. Your feedback will also be very useful for us to know if our solution produces quality code or if we need to improve the way it works.

Thank you for your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant