@@ -64,10 +64,9 @@ Collection<Object> initializeCollectionForResultMapping(ObjectFactory objectFact
6464 "Cannot add a collection result to non-collection based resultMapping: " + constructorMapping );
6565 }
6666
67- final PendingCreationKey creationKey = new PendingCreationKey (constructorMapping );
68- return linkedCollectionsByKey .computeIfAbsent (creationKey , (k ) -> {
67+ return linkedCollectionsByKey .computeIfAbsent (new PendingCreationKey (constructorMapping ), k -> {
6968 // 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 ));
7170
7271 // will be checked before we finally create the object) as we cannot reliably do that here
7372 return (Collection <Object >) objectFactory .create (parameterType );
@@ -77,7 +76,7 @@ Collection<Object> initializeCollectionForResultMapping(ObjectFactory objectFact
7776 void linkCreation (ResultMapping constructorMapping , PendingConstructorCreation pcc ) {
7877 final PendingCreationKey creationKey = new PendingCreationKey (constructorMapping );
7978 final List <PendingConstructorCreation > pendingConstructorCreations = linkedCreationsByKey
80- .computeIfAbsent (creationKey , ( k ) -> new ArrayList <>());
79+ .computeIfAbsent (creationKey , k -> new ArrayList <>());
8180
8281 if (pendingConstructorCreations .contains (pcc )) {
8382 throw new ExecutorException ("Cannot link inner constructor creation with same value, MyBatis internal error!" );
@@ -92,13 +91,10 @@ void linkCollectionValue(ResultMapping constructorMapping, Object value) {
9291 return ;
9392 }
9493
95- final PendingCreationKey creationKey = new PendingCreationKey (constructorMapping );
96- if (!linkedCollectionsByKey .containsKey (creationKey )) {
94+ linkedCollectionsByKey .computeIfAbsent (new PendingCreationKey (constructorMapping ), k -> {
9795 throw new ExecutorException ("Cannot link collection value for key: " + constructorMapping
9896 + ", resultMap has not been seen/initialized yet! Mybatis internal error!" );
99- }
100-
101- linkedCollectionsByKey .get (creationKey ).add (value );
97+ }).add (value );
10298 }
10399
104100 @ Override
@@ -128,10 +124,10 @@ Object create(ObjectFactory objectFactory) {
128124
129125 // time to finally build this collection
130126 final PendingCreationKey pendingCreationKey = creationMetaInfo .getPendingCreationKey ();
131- if (linkedCreationsByKey .containsKey (pendingCreationKey )) {
127+ final List <PendingConstructorCreation > linkedCreations = linkedCreationsByKey .get (pendingCreationKey );
128+ if (linkedCreations != null ) {
132129 @ SuppressWarnings ("unchecked" )
133130 final Collection <Object > emptyCollection = (Collection <Object >) existingArg ;
134- final List <PendingConstructorCreation > linkedCreations = linkedCreationsByKey .get (pendingCreationKey );
135131
136132 for (PendingConstructorCreation linkedCreation : linkedCreations ) {
137133 emptyCollection .add (linkedCreation .create (objectFactory ));
0 commit comments