Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce rawType to be a Class in ParameterizedTypeImpl #2759

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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