Skip to content

Fix the Multiset code sample in TypeAdapterFactory's JavaDoc - #3114

Closed
alorentiar wants to merge 2 commits into
google:mainfrom
alorentiar:docs/multiset-sample
Closed

Fix the Multiset code sample in TypeAdapterFactory's JavaDoc#3114
alorentiar wants to merge 2 commits into
google:mainfrom
alorentiar:docs/multiset-sample

Conversation

@alorentiar

Copy link
Copy Markdown

The Multiset sample in TypeAdapterFactory's javadoc compared the raw type against Multiset.class, so it rejected ImmutableMultiset and HashMultiset even though those are what most people actually use. The example then fell through to Gson's default collection handling and duplicates were not aggregated.

The sample now uses isAssignableFrom, the same pattern as CollectionTypeAdapterFactory, and falls back to Object.class when the token carries no type information.

Fixes #1335

The sample rejected ImmutableMultiset and HashMultiset because it compared
the raw type against Multiset.class instead of using isAssignableFrom, so
the multiset fell through to the default collection adapter and duplicates
were not aggregated. Mirror the CollectionTypeAdapterFactory pattern and
fall back to Object.class for non-parameterized tokens.
@google-cla

google-cla Bot commented Sep 6, 2026

Copy link
Copy Markdown

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.

@alorentiar

Copy link
Copy Markdown
Author

Closing this, sorry for the noise.

@alorentiar alorentiar closed this Sep 7, 2026
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.

The Multiset code sample in TypeAdapterFactory's JavaDoc does not work

1 participant