Skip to content

Commit

Permalink
Enforce rawType to be a Class in ParameterizedTypeImpl
Browse files Browse the repository at this point in the history
Enforce rawType to be a Class in ParameterizedTypeImpl

Enforce rawType to be a Class in ParameterizedTypeImpl
  • Loading branch information
panic08 committed Oct 13, 2024
1 parent 7e98ebd commit e44c37e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
12 changes: 6 additions & 6 deletions gson/src/main/java/com/google/gson/internal/$Gson$Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public final class $Gson$Types {
* @return a {@link java.io.Serializable serializable} parameterized type.
*/
public static ParameterizedType newParameterizedTypeWithOwner(
Type ownerType, Type rawType, Type... typeArguments) {
Type ownerType, Class<?> rawType, Type... typeArguments) {
return new ParameterizedTypeImpl(ownerType, rawType, typeArguments);
}

Expand Down Expand Up @@ -112,7 +112,7 @@ public static Type canonicalize(Type type) {
} else if (type instanceof ParameterizedType) {
ParameterizedType p = (ParameterizedType) type;
return new ParameterizedTypeImpl(
p.getOwnerType(), p.getRawType(), p.getActualTypeArguments());
p.getOwnerType(), (Class<?>) p.getRawType(), p.getActualTypeArguments());

} else if (type instanceof GenericArrayType) {
GenericArrayType g = (GenericArrayType) type;
Expand Down Expand Up @@ -411,7 +411,8 @@ private static Type resolve(

toResolve =
ownerChanged || argsChanged
? newParameterizedTypeWithOwner(newOwnerType, original.getRawType(), args)
? newParameterizedTypeWithOwner(
newOwnerType, (Class<?>) original.getRawType(), args)
: original;
break;

Expand Down Expand Up @@ -519,10 +520,9 @@ private static final class ParameterizedTypeImpl implements ParameterizedType, S
@SuppressWarnings("serial")
private final Type[] typeArguments;

public ParameterizedTypeImpl(Type ownerType, Type rawType, Type... typeArguments) {
// TODO: Should this enforce that rawType is a Class? See JDK implementation of
// the ParameterizedType interface and https://bugs.openjdk.org/browse/JDK-8250659
public ParameterizedTypeImpl(Type ownerType, Class<?> rawType, Type... typeArguments) {
requireNonNull(rawType);

if (ownerType == null && requiresOwnerType(rawType)) {
throw new IllegalArgumentException("Must specify owner type for " + rawType);
}
Expand Down
3 changes: 2 additions & 1 deletion gson/src/main/java/com/google/gson/reflect/TypeToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,8 @@ public static TypeToken<?> getParameterized(Type rawType, Type... typeArguments)
}
}

return new TypeToken<>($Gson$Types.newParameterizedTypeWithOwner(null, rawType, typeArguments));
return new TypeToken<>(
$Gson$Types.newParameterizedTypeWithOwner(null, rawClass, typeArguments));
}

/**
Expand Down

0 comments on commit e44c37e

Please sign in to comment.