Skip to content

Entry set spliterators don't report the DISTINCT characteristic #8088

@kilink

Description

@kilink

Guava Version

33.5.0-jre

Description

I noticed a minor issue with some of the entry set spliterators not consistently reporting DISTINCT (ImmutableMap, ImmutableBiMap, etc). This is because they are backed by an ImmutableList, but we could easily override the characteristics of the Spliterator since it is known to be distinct.

Example

ImmutableBiMap.of().entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // true
ImmutableBiMap.of("a", "b").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // false
ImmutableBiMap.of("a", "b", "c", "d").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // false
ImmutableMap.of().entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // false
ImmutableMap.of("a", "b").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT)) // false
ImmutableMap.of("a", "b", "c", "d").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // false


Contrast that with the JDK:


Map.of().entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // true
Map.of("a", "b").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // true
Map.of("a", "b", "c", "d").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // true
Map.of("a", "b", "c", "d", "e", "f").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // true

Expected Behavior

I would expect the spliterator characteristics to match the JDK and report DISTINCT for an entry set.

Actual Behavior

Entry set spliterators don't consistently report DISTINCT.

Packages

com.google.common.collect

Platforms

No response

Checklist

  • I agree to follow the code of conduct.

  • I can reproduce the bug with the latest version of Guava available.

Metadata

Metadata

Assignees

Labels

P3no SLOtype=defectBug, not working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions