From 6cb7ee0f9762224669c0adbc11c1bf9e73133cb6 Mon Sep 17 00:00:00 2001 From: daguimu Date: Thu, 26 Mar 2026 10:08:41 +0800 Subject: [PATCH] fix: Correct Multiset example in TypeAdapterFactory Javadoc The code sample used `typeToken.getRawType() != Multiset.class` which only matches the exact Multiset class, not its subtypes like HashMultiset or LinkedHashMultiset. This causes the factory to return null for all practical Multiset implementations, falling through to CollectionTypeAdapterFactory instead. Change to `!Multiset.class.isAssignableFrom(typeToken.getRawType())` to correctly match all Multiset subtypes. Fixes #1335 --- gson/src/main/java/com/google/gson/TypeAdapterFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gson/src/main/java/com/google/gson/TypeAdapterFactory.java b/gson/src/main/java/com/google/gson/TypeAdapterFactory.java index 4473e59b7a..248414b89b 100644 --- a/gson/src/main/java/com/google/gson/TypeAdapterFactory.java +++ b/gson/src/main/java/com/google/gson/TypeAdapterFactory.java @@ -106,7 +106,7 @@ * public class MultisetTypeAdapterFactory implements TypeAdapterFactory { * public TypeAdapter create(Gson gson, TypeToken typeToken) { * Type type = typeToken.getType(); - * if (typeToken.getRawType() != Multiset.class + * if (!Multiset.class.isAssignableFrom(typeToken.getRawType()) * || !(type instanceof ParameterizedType)) { * return null; * }