The Multiset code sample in TypeAdapterFactory's JavaDoc does not work
- Dominant language
- Java
- Stars
- 24.2k
- Forks
- 4.5k
- Avg merge
- 6d 4h
- Merged PRs (30d)
- 12
Description
In Gson 2.8.5, the JavaDoc to `TypeAdapterFactory` presents a code sample of `MultisetTypeAdapterFactory`. However, this code sample does not work (instead of `MultisetTypeAdapterFactory`, `CollectionTypeAdapterFactory` is triggered). The problem is in these lines:
```
if (typeToken.getRawType() != Multiset.class || !(type instanceof ParameterizedType)) {
return null;
}
Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0];
```
Instead, the following should be used (like in `CollectionTypeAdapterFactory`):
```
Class rawType = typeToken.getRawType();
if (!Multiset.class.isAssignableFrom(rawType)) {
return null;
}
Type elementType = $Gson$Types.getCollectionElementType(type, rawType);
```
Contributor guide
Assessment
This issue has not been assessed yet.