@@ -64,10 +64,9 @@ Collection<Object> initializeCollectionForResultMapping(ObjectFactory objectFact
64
64
"Cannot add a collection result to non-collection based resultMapping: " + constructorMapping );
65
65
}
66
66
67
- final PendingCreationKey creationKey = new PendingCreationKey (constructorMapping );
68
- return linkedCollectionsByKey .computeIfAbsent (creationKey , (k ) -> {
67
+ return linkedCollectionsByKey .computeIfAbsent (new PendingCreationKey (constructorMapping ), k -> {
69
68
// this will allow us to verify the types of the collection before creating the final object
70
- linkedCollectionMetaInfo .put (index , new PendingCreationMetaInfo (resultMap .getType (), creationKey ));
69
+ linkedCollectionMetaInfo .put (index , new PendingCreationMetaInfo (resultMap .getType (), k ));
71
70
72
71
// will be checked before we finally create the object) as we cannot reliably do that here
73
72
return (Collection <Object >) objectFactory .create (parameterType );
@@ -77,7 +76,7 @@ Collection<Object> initializeCollectionForResultMapping(ObjectFactory objectFact
77
76
void linkCreation (ResultMapping constructorMapping , PendingConstructorCreation pcc ) {
78
77
final PendingCreationKey creationKey = new PendingCreationKey (constructorMapping );
79
78
final List <PendingConstructorCreation > pendingConstructorCreations = linkedCreationsByKey
80
- .computeIfAbsent (creationKey , ( k ) -> new ArrayList <>());
79
+ .computeIfAbsent (creationKey , k -> new ArrayList <>());
81
80
82
81
if (pendingConstructorCreations .contains (pcc )) {
83
82
throw new ExecutorException ("Cannot link inner constructor creation with same value, MyBatis internal error!" );
@@ -92,13 +91,10 @@ void linkCollectionValue(ResultMapping constructorMapping, Object value) {
92
91
return ;
93
92
}
94
93
95
- final PendingCreationKey creationKey = new PendingCreationKey (constructorMapping );
96
- if (!linkedCollectionsByKey .containsKey (creationKey )) {
94
+ linkedCollectionsByKey .computeIfAbsent (new PendingCreationKey (constructorMapping ), k -> {
97
95
throw new ExecutorException ("Cannot link collection value for key: " + constructorMapping
98
96
+ ", resultMap has not been seen/initialized yet! Mybatis internal error!" );
99
- }
100
-
101
- linkedCollectionsByKey .get (creationKey ).add (value );
97
+ }).add (value );
102
98
}
103
99
104
100
@ Override
@@ -128,10 +124,10 @@ Object create(ObjectFactory objectFactory) {
128
124
129
125
// time to finally build this collection
130
126
final PendingCreationKey pendingCreationKey = creationMetaInfo .getPendingCreationKey ();
131
- if (linkedCreationsByKey .containsKey (pendingCreationKey )) {
127
+ final List <PendingConstructorCreation > linkedCreations = linkedCreationsByKey .get (pendingCreationKey );
128
+ if (linkedCreations != null ) {
132
129
@ SuppressWarnings ("unchecked" )
133
130
final Collection <Object > emptyCollection = (Collection <Object >) existingArg ;
134
- final List <PendingConstructorCreation > linkedCreations = linkedCreationsByKey .get (pendingCreationKey );
135
131
136
132
for (PendingConstructorCreation linkedCreation : linkedCreations ) {
137
133
emptyCollection .add (linkedCreation .create (objectFactory ));
0 commit comments