From b626f289b7544e756d95ed00207391b9b9801f0c Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Fri, 3 Jun 2016 18:17:50 +0100 Subject: [PATCH] HHH-10427 All access to mutable fields needs lock protection --- .../service/internal/AbstractServiceRegistryImpl.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java index 26d3a032be..889716d8c8 100644 --- a/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java @@ -36,6 +36,7 @@ import org.hibernate.service.spi.Stoppable; * Basic implementation of the ServiceRegistry and ServiceRegistryImplementor contracts * * @author Steve Ebersole + * @author Sanne Grinovero */ public abstract class AbstractServiceRegistryImpl implements ServiceRegistryImplementor, ServiceBinding.ServiceLifecycleOwner { @@ -56,9 +57,12 @@ public abstract class AbstractServiceRegistryImpl // IMPL NOTE : the list used for ordered destruction. Cannot used map above because we need to // iterate it in reverse order which is only available through ListIterator // assume 20 services for initial sizing + // All access guarded by synchronization on the serviceBindingList itself. private final List serviceBindingList = CollectionHelper.arrayList( 20 ); + // Guarded by synchronization on this. private boolean autoCloseRegistry; + // Guarded by synchronization on this. private Set childRegistries; @SuppressWarnings( {"UnusedDeclaration"}) @@ -376,7 +380,7 @@ public abstract class AbstractServiceRegistryImpl } @Override - public void registerChild(ServiceRegistryImplementor child) { + public synchronized void registerChild(ServiceRegistryImplementor child) { if ( childRegistries == null ) { childRegistries = new HashSet(); } @@ -389,7 +393,7 @@ public abstract class AbstractServiceRegistryImpl } @Override - public void deRegisterChild(ServiceRegistryImplementor child) { + public synchronized void deRegisterChild(ServiceRegistryImplementor child) { if ( childRegistries == null ) { throw new IllegalStateException( "No child ServiceRegistry registrations found" ); }