Skip to content

Add ConcurrentMap spliterator checks#8371

Open
holly-agyei wants to merge 3 commits into
google:masterfrom
holly-agyei:fix-7855-concurrentmap-spliterators
Open

Add ConcurrentMap spliterator checks#8371
holly-agyei wants to merge 3 commits into
google:masterfrom
holly-agyei:fix-7855-concurrentmap-spliterators

Conversation

@holly-agyei
Copy link
Copy Markdown
Contributor

Adds ConcurrentMap-specific testlib coverage for derived keySet and entrySet spliterators, and updates LocalCache to satisfy it in both the JRE and Android source trees.

Fixes #7855

Implementation:

  • add a new ConcurrentMapSpliteratorTester that checks keySet() and entrySet() spliterators report CONCURRENT and do not report SIZED
  • wire that tester into ConcurrentMapTestSuiteBuilder so ConcurrentMap suites pick it up automatically
  • add a focused ConcurrentMapTestSuiteBuilder self-test that verifies both the passing and failing cases
  • override LocalCache derived-set spliterators in both JRE and Android variants to use concurrent unknown-size spliterators

Process:

  • read and followed the repository guidance and matched the surrounding testlib and cache code style
  • kept the scope to the issue and added regression coverage for the new behavior

Validation:

  • direct junit.textui.TestRunner execution of com.google.common.collect.testing.ConcurrentMapTestSuiteBuilderTest passed
  • direct javac compilation of the changed testlib and LocalCache sources passed
  • full Maven test execution was not possible in this environment because Maven project loading failed on unresolved build extensions during local verification

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 23, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

CI's animal-sniffer check on the android variant (gummy-bears-api-23) rejected
the Spliterator override added in the previous commit because java.util.Spliterator
and Spliterators.spliteratorUnknownSize(...) are not part of Android API 23.

Following the established pattern in ImmutableCollection.java, Ints.java, and
Longs.java under android/guava/src, annotate the method with the package-local
@IgnoreJRERequirement.  The method is only invoked from APIs whose signatures
already carry Java 8 types, so callers are already gated by the same constraint.

The guava/src variant is unaffected because it uses the java18 signature, which
includes Spliterator.

Made-with: Cursor
@holly-agyei holly-agyei force-pushed the fix-7855-concurrentmap-spliterators branch from df3d1f5 to bcd722f Compare April 24, 2026 17:56
@holly-agyei
Copy link
Copy Markdown
Contributor Author

CI fix: the earlier run failed because the spliterator() override added to android/guava/src/com/google/common/cache/LocalCache.java referenced java.util.Spliterator / Spliterators.spliteratorUnknownSize(...), which Animal Sniffer flagged against the Android API 23 signature (gummy-bears-api-23).

Pushed a follow-up commit (bcd722f) that annotates the new method with the package-local @IgnoreJRERequirement, following the convention already used for spliterator() in android/guava/src/com/google/common/collect/ImmutableCollection.java and primitive array wrappers. The main guava/src variant is unchanged because it's checked against the java18 signature, which includes Spliterator.

Verified locally:

  • ./mvnw animal-sniffer:check -pl guava -f android/pom.xml — BUILD SUCCESS
  • ./mvnw install -DskipTests=true -f android/pom.xml — BUILD SUCCESS (all 5 reactor modules)
  • ./mvnw -pl guava-tests test -Dtest='LocalCacheTest,CacheBuilderSpecTest,CacheLoadingTest' -f android/pom.xml — 8,139 tests pass
  • ./mvnw -pl guava-tests test -Dtest='LocalCacheTest,CacheBuilderSpecTest,CacheLoadingTest,ConcurrentMapTestSuiteBuilderTest,ConcurrentHashMultisetTest,MapMakerInternalMapTest' (main variant) — 13,998 tests pass

@cgdecker
Copy link
Copy Markdown
Member

I think LocalCache.Values (which extends AbstractCollection) should also have its spliterator() implementation changed in a similar way (CONCURRENT and NONNULL).

* map. Can't be invoked directly; please see {@link
* com.google.common.collect.testing.ConcurrentMapTestSuiteBuilder}.
*
* @author Louis Wasserman
Copy link
Copy Markdown
Member

@cgdecker cgdecker Apr 27, 2026

Choose a reason for hiding this comment

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

This @author tag shouldn't be here. Besides being inaccurate here, we don't use @author tags at all anymore in new code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@cgdecker, thanks for the catch. Both fixed in d9e665d.

On the @author tag: I had copied the file header from a sibling tester (MapSpliteratorTester) as a starting point and missed removing the @author Louis Wasserman line. Sorry about that. I Dropped the tag entirely since new Guava code doesn't use them anymore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@cgdecker, thanks for the catch. Both fixed in d9e665d.

On the https://github.com/author tag: I had copied the file header from a sibling tester (MapSpliteratorTester) as a starting point and missed removing the https://github.com/author Louis Wasserman line. Sorry about that. I Dropped the tag entirely since new Guava code doesn't use them anymore.

- Override spliterator() on LocalCache.Values (CONCURRENT | NONNULL) in
  both the main and android variants, mirroring the existing
  AbstractCacheSet override (per cgdecker review on google#8371). The android
  variant uses @IgnoreJRERequirement to satisfy animal-sniffer's
  gummy-bears-api-23 signature.
- Remove the inaccurate @author tag from the new
  ConcurrentMapSpliteratorTester; new Guava code no longer carries
  @author tags.

Made-with: Cursor
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.

testlib: add tests for ConcurrentMap to make sure its derived Sets are concurrent

2 participants