All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S2250.html Maven / Gradle / Ivy

The newest version!

For most collections the size() method requires constant time, but the time required to execute ConcurrentLinkedQueue.size() is directly proportional to the number of elements in the queue. When the queue is large, this could therefore be an expensive operation. Further, the results may be inaccurate if the queue is modified during execution.

By the way, if the size() is used only to check that the collection is empty, then the isEmpty() method should be used.

Noncompliant Code Example

ConcurrentLinkedQueue queue = new ConcurrentLinkedQueue();
//...
log.info("Queue contains " + queue.size() + " elements");




© 2015 - 2025 Weber Informatics LLC | Privacy Policy