[concurrency-interest] CHM trySplit of a map with odd size

Doug Lea dl at cs.oswego.edu
Mon Feb 22 10:04:44 EST 2016

On 02/22/2016 04:33 AM, Ben Manes wrote:

> When writing parameterized tests
> a custom Spliterator view, the tests failed for maps of size 1.
> ConcurrentHashMap trySplit will return a new Spliterator with an estimated size
> of zero and set the source spliterator to zero as well.

I believe that plain HashMap and some other classes can do this as well.
They return regions that should (statistically) hold elements but might not.
Similarly for some IO-based spliterators.

> The contract states that
> trySplit should return null in that case

It says that it must eventually return null.

> The JavaDoc says the estimate may be arbitrarily inaccurate. It would be nice if
> either the implementations were more accurate or included a comment hinting to
> their behavior.

That's what the SIZED characteristic is for. Non-exact spliterators
don't set SIZED.

I agree that these rules make writing unit tests more complicated, but
the underlying idea is not to force implementations to do things that
are slow or impossible for some sources or sata structures.


More information about the Concurrency-interest mailing list