Skip to content

Commit

Permalink
Fix typeArguments array not being cloned when resolving Parameterized…
Browse files Browse the repository at this point in the history
…Type with changed owner (#2706)
  • Loading branch information
TBlueF authored Jun 27, 2024
1 parent 3621e51 commit e8cdabf
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions gson/src/main/java/com/google/gson/internal/$Gson$Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,23 +392,24 @@ private static Type resolve(
ParameterizedType original = (ParameterizedType) toResolve;
Type ownerType = original.getOwnerType();
Type newOwnerType = resolve(context, contextRawType, ownerType, visitedTypeVariables);
boolean changed = !equal(newOwnerType, ownerType);
boolean ownerChanged = !equal(newOwnerType, ownerType);

Type[] args = original.getActualTypeArguments();
boolean argsChanged = false;
for (int t = 0, length = args.length; t < length; t++) {
Type resolvedTypeArgument =
resolve(context, contextRawType, args[t], visitedTypeVariables);
if (!equal(resolvedTypeArgument, args[t])) {
if (!changed) {
if (!argsChanged) {
args = args.clone();
changed = true;
argsChanged = true;
}
args[t] = resolvedTypeArgument;
}
}

toResolve =
changed
ownerChanged || argsChanged
? newParameterizedTypeWithOwner(newOwnerType, original.getRawType(), args)
: original;
break;
Expand Down

0 comments on commit e8cdabf

Please sign in to comment.