HHH-18475 fix race condition in AbstractRowMapper

This commit is contained in:
Olivier Bourgain 2024-08-12 10:38:18 +02:00 committed by Christian Beikov
parent 30241bbe9f
commit fbdec58da2
1 changed files with 3 additions and 2 deletions

View File

@ -50,7 +50,7 @@ public abstract class AbstractRowReader implements RowReader {
// cache map for looking up EntityReferenceInitializer by EntityReference to help with resolving
// bidirectional EntityReference and fetches.
private Map<EntityReference,EntityReferenceInitializer> entityInitializerByEntityReference;
private volatile Map<EntityReference,EntityReferenceInitializer> entityInitializerByEntityReference;
public AbstractRowReader(ReaderCollector readerCollector) {
this.entityReferenceInitializers = readerCollector.getEntityReferenceInitializers().toArray( EMPTY_REFERENCE_INITIALIZERS );
@ -149,13 +149,14 @@ public abstract class AbstractRowReader implements RowReader {
private EntityReferenceInitializer getInitializerByEntityReference(EntityReference targetEntityReference) {
if ( entityInitializerByEntityReference == null ) {
entityInitializerByEntityReference = new HashMap<>( entityReferenceInitializers.length );
Map<EntityReference,EntityReferenceInitializer> entityInitializerByEntityReference = new HashMap<>( entityReferenceInitializers.length );
for ( EntityReferenceInitializer entityReferenceInitializer : entityReferenceInitializers ) {
entityInitializerByEntityReference.put(
entityReferenceInitializer.getEntityReference(),
entityReferenceInitializer
);
}
this.entityInitializerByEntityReference = entityInitializerByEntityReference;
}
return entityInitializerByEntityReference.get(
targetEntityReference