|
56 | 56 | * @author Juergen Hoeller
|
57 | 57 | * @since 4.0
|
58 | 58 | */
|
59 |
| -abstract class SerializableTypeWrapper { |
| 59 | +final class SerializableTypeWrapper { |
60 | 60 |
|
61 | 61 | private static final Class<?>[] SUPPORTED_SERIALIZABLE_TYPES = {
|
62 | 62 | GenericArrayType.class, ParameterizedType.class, TypeVariable.class, WildcardType.class};
|
63 | 63 |
|
| 64 | + /** |
| 65 | + * Let's test whether java.lang.Class itself is serializable... |
| 66 | + * Otherwise we can skip our serializable type wrapping to begin with. |
| 67 | + * This will be {@code true} on regular JVMs but {@code false} on GraalVM. |
| 68 | + * @since 5.1 |
| 69 | + */ |
| 70 | + private static final boolean javaLangClassSerializable = Serializable.class.isAssignableFrom(Class.class); |
| 71 | + |
64 | 72 | static final ConcurrentReferenceHashMap<Type, Type> cache = new ConcurrentReferenceHashMap<>(256);
|
65 | 73 |
|
66 | 74 |
|
| 75 | + private SerializableTypeWrapper() { |
| 76 | + } |
| 77 | + |
| 78 | + |
67 | 79 | /**
|
68 | 80 | * Return a {@link Serializable} variant of {@link Field#getGenericType()}.
|
69 | 81 | */
|
@@ -133,15 +145,17 @@ public static <T extends Type> T unwrap(T type) {
|
133 | 145 |
|
134 | 146 | /**
|
135 | 147 | * Return a {@link Serializable} {@link Type} backed by a {@link TypeProvider} .
|
| 148 | + * <p>If type artifacts are generally not serializable in the current runtime |
| 149 | + * environment, this delegate will simply return the original {@code Type} as-is. |
136 | 150 | */
|
137 | 151 | @Nullable
|
138 | 152 | static Type forTypeProvider(final TypeProvider provider) {
|
139 |
| - Assert.notNull(provider, "Provider must not be null"); |
| 153 | + Assert.notNull(provider, "TypeProvider must not be null"); |
140 | 154 | Type providedType = provider.getType();
|
141 | 155 | if (providedType == null) {
|
142 | 156 | return null;
|
143 | 157 | }
|
144 |
| - if (providedType instanceof Serializable) { |
| 158 | + if (!javaLangClassSerializable || providedType instanceof Serializable) { |
145 | 159 | return providedType;
|
146 | 160 | }
|
147 | 161 | Type cached = cache.get(providedType);
|
|
0 commit comments