File tree 2 files changed +25
-2
lines changed
main/java/org/springframework/data/util
test/java/org/springframework/data/util
2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
60
60
private final Map <Constructor <?>, List <TypeInformation <?>>> constructorParameters = new ConcurrentHashMap <>();
61
61
private final Lazy <List <TypeInformation <?>>> typeArguments ;
62
62
63
- private final Lazy <List <Class >> resolvedGenerics ;
63
+ private final Lazy <List <TypeInformation <?> >> resolvedGenerics ;
64
64
65
65
protected TypeDiscoverer (ResolvableType type ) {
66
66
@@ -71,7 +71,9 @@ protected TypeDiscoverer(ResolvableType type) {
71
71
this .valueType = Lazy .of (this ::doGetMapValueType );
72
72
this .typeArguments = Lazy .of (this ::doGetTypeArguments );
73
73
this .resolvedGenerics = Lazy .of (() -> Arrays .stream (resolvableType .getGenerics ()) //
74
- .map (ResolvableType ::toClass ).collect (Collectors .toList ()));
74
+ .map (TypeInformation ::of ) // use TypeInformation comparison to remove any attachments to variableResolver
75
+ // holding the type source
76
+ .collect (Collectors .toList ()));
75
77
}
76
78
77
79
static TypeDiscoverer <?> td (ResolvableType type ) {
Original file line number Diff line number Diff line change 29
29
import org .junit .jupiter .api .Test ;
30
30
import org .junit .jupiter .api .extension .ExtendWith ;
31
31
import org .mockito .junit .jupiter .MockitoExtension ;
32
+
32
33
import org .springframework .beans .factory .annotation .Autowire ;
33
34
import org .springframework .core .ResolvableType ;
34
35
import org .springframework .data .geo .GeoResults ;
@@ -348,6 +349,15 @@ void differentEqualsAndHashCodeForTypeDiscovererAndClassTypeInformation() {
348
349
assertThat (discoverer .hashCode ()).isNotEqualTo (classTypeInformation .hashCode ());
349
350
}
350
351
352
+ @ Test // GH-3051
353
+ void considersNestedGenericsInEquality () throws ReflectiveOperationException {
354
+
355
+ ResolvableType containerList = ResolvableType .forField (WithContainer .class .getDeclaredField ("containerList" ));
356
+ ResolvableType containerMap = ResolvableType .forField (WithContainer .class .getDeclaredField ("containerMap" ));
357
+
358
+ assertThat (TypeInformation .of (containerList )).isNotEqualTo (TypeInformation .of (containerMap ));
359
+ }
360
+
351
361
class Person {
352
362
353
363
Addresses addresses ;
@@ -441,4 +451,15 @@ class EnumMapWrapper {
441
451
class GeoResultsWrapper {
442
452
GeoResults <Leaf > results ;
443
453
}
454
+
455
+ static class WithContainer {
456
+ MyContainer <List <String >> containerList ;
457
+
458
+ MyContainer <List <Map <Long , Double >>> containerMap ;
459
+ }
460
+
461
+ static class MyContainer <T > {
462
+ T data ;
463
+ }
464
+
444
465
}
You can’t perform that action at this time.
0 commit comments