Skip to content

Commit 7ca0094

Browse files
committed
ResolvableType.clearCache() clears SerializableTypeWrapper cache as well
Issue: SPR-15503
1 parent 3b8b350 commit 7ca0094

File tree

2 files changed

+11
-35
lines changed

2 files changed

+11
-35
lines changed

spring-core/src/main/java/org/springframework/core/ResolvableType.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1356,11 +1356,12 @@ static ResolvableType forType(Type type, TypeProvider typeProvider, VariableReso
13561356
}
13571357

13581358
/**
1359-
* Clear the internal {@code ResolvableType} cache.
1359+
* Clear the internal {@code ResolvableType}/{@code SerializableTypeWrapper} cache.
13601360
* @since 4.2
13611361
*/
13621362
public static void clearCache() {
13631363
cache.clear();
1364+
SerializableTypeWrapper.cache.clear();
13641365
}
13651366

13661367

spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ abstract class SerializableTypeWrapper {
5959
private static final Class<?>[] SUPPORTED_SERIALIZABLE_TYPES = {
6060
GenericArrayType.class, ParameterizedType.class, TypeVariable.class, WildcardType.class};
6161

62-
private static final ConcurrentReferenceHashMap<Type, Type> cache =
63-
new ConcurrentReferenceHashMap<>(256);
62+
static final ConcurrentReferenceHashMap<Type, Type> cache = new ConcurrentReferenceHashMap<>(256);
6463

6564

6665
/**
@@ -84,12 +83,7 @@ public static Type forMethodParameter(MethodParameter methodParameter) {
8483
*/
8584
@SuppressWarnings("serial")
8685
public static Type forGenericSuperclass(final Class<?> type) {
87-
return forTypeProvider(new DefaultTypeProvider() {
88-
@Override
89-
public Type getType() {
90-
return type.getGenericSuperclass();
91-
}
92-
});
86+
return forTypeProvider(type::getGenericSuperclass);
9387
}
9488

9589
/**
@@ -100,12 +94,7 @@ public static Type[] forGenericInterfaces(final Class<?> type) {
10094
Type[] result = new Type[type.getGenericInterfaces().length];
10195
for (int i = 0; i < result.length; i++) {
10296
final int index = i;
103-
result[i] = forTypeProvider(new DefaultTypeProvider() {
104-
@Override
105-
public Type getType() {
106-
return type.getGenericInterfaces()[index];
107-
}
108-
});
97+
result[i] = forTypeProvider(() -> type.getGenericInterfaces()[index]);
10998
}
11099
return result;
111100
}
@@ -118,12 +107,7 @@ public static Type[] forTypeParameters(final Class<?> type) {
118107
Type[] result = new Type[type.getTypeParameters().length];
119108
for (int i = 0; i < result.length; i++) {
120109
final int index = i;
121-
result[i] = forTypeProvider(new DefaultTypeProvider() {
122-
@Override
123-
public Type getType() {
124-
return type.getTypeParameters()[index];
125-
}
126-
});
110+
result[i] = forTypeProvider(() -> type.getTypeParameters()[index]);
127111
}
128112
return result;
129113
}
@@ -183,6 +167,7 @@ interface SerializableTypeProxy {
183167
/**
184168
* A {@link Serializable} interface providing access to a {@link Type}.
185169
*/
170+
@SuppressWarnings("serial")
186171
interface TypeProvider extends Serializable {
187172

188173
/**
@@ -191,20 +176,10 @@ interface TypeProvider extends Serializable {
191176
Type getType();
192177

193178
/**
194-
* Return the source of the type or {@code null}.
179+
* Return the source of the type, or {@code null} if not known.
180+
* <p>The default implementations returns {@code null}.
195181
*/
196-
Object getSource();
197-
}
198-
199-
200-
/**
201-
* Default implementation of {@link TypeProvider} with a {@code null} source.
202-
*/
203-
@SuppressWarnings("serial")
204-
private static abstract class DefaultTypeProvider implements TypeProvider {
205-
206-
@Override
207-
public Object getSource() {
182+
default Object getSource() {
208183
return null;
209184
}
210185
}

0 commit comments

Comments
 (0)