Skip to content

Commit 29ab176

Browse files
committed
HHH-8363 SessionFactoryServiceRegistryImpl should not call parent#destroy, test failures, formatting
1 parent 360567b commit 29ab176

File tree

6 files changed

+32
-32
lines changed

6 files changed

+32
-32
lines changed

hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,15 @@ public <S> LinkedHashSet<S> loadJavaServices(Class<S> serviceContract) {
343343

344344
@Override
345345
public void stop() {
346-
for (ServiceLoader serviceLoader : serviceLoaders.values()) {
346+
for ( ServiceLoader serviceLoader : serviceLoaders.values() ) {
347347
serviceLoader.reload(); // clear service loader providers
348348
}
349349
serviceLoaders.clear();
350-
if (aggregatedClassLoader!=null){
351-
aggregatedClassLoader.destroy();
352-
aggregatedClassLoader = null;
353-
}
350+
351+
if ( aggregatedClassLoader != null ) {
352+
aggregatedClassLoader.destroy();
353+
aggregatedClassLoader = null;
354+
}
354355
}
355356

356357
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

hibernate-core/src/main/java/org/hibernate/boot/registry/internal/StandardServiceRegistryImpl.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@
2626
import java.util.List;
2727
import java.util.Map;
2828

29-
import org.hibernate.boot.registry.StandardServiceInitiator;
3029
import org.hibernate.boot.registry.BootstrapServiceRegistry;
30+
import org.hibernate.boot.registry.StandardServiceInitiator;
3131
import org.hibernate.boot.registry.StandardServiceRegistry;
3232
import org.hibernate.service.Service;
3333
import org.hibernate.service.internal.AbstractServiceRegistryImpl;
3434
import org.hibernate.service.internal.ProvidedService;
3535
import org.hibernate.service.spi.Configurable;
3636
import org.hibernate.service.spi.ServiceBinding;
3737
import org.hibernate.service.spi.ServiceInitiator;
38+
import org.hibernate.service.spi.ServiceRegistryImplementor;
3839

3940
/**
4041
* Standard Hibernate implementation of the standard service registry.
@@ -89,4 +90,11 @@ public <R extends Service> void configureService(ServiceBinding<R> serviceBindin
8990
}
9091
}
9192

93+
@Override
94+
public void destroy() {
95+
super.destroy();
96+
if ( getParentServiceRegistry() != null ) {
97+
( (ServiceRegistryImplementor) getParentServiceRegistry() ).destroy();
98+
}
99+
}
92100
}

hibernate-core/src/main/java/org/hibernate/service/internal/AbstractServiceRegistryImpl.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ public AbstractServiceRegistryImpl(BootstrapServiceRegistry bootstrapServiceRegi
8787
protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) {
8888
final ServiceBinding serviceBinding = new ServiceBinding( this, initiator );
8989
serviceBindingMap.put( initiator.getServiceInitiated(), serviceBinding );
90-
synchronized ( serviceBindingList ) {
91-
serviceBindingList.add( serviceBinding );
92-
}
9390
}
9491

9592
protected <R extends Service> void createServiceBinding(ProvidedService<R> providedService) {
@@ -278,10 +275,6 @@ public void destroy() {
278275
serviceBindingList.clear();
279276
}
280277
serviceBindingMap.clear();
281-
282-
if (parent!=null){
283-
parent.destroy();
284-
}
285278
}
286279

287280
@Override

hibernate-core/src/test/java/org/hibernate/test/service/ClassLoaderServiceImplTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package org.hibernate.test.service;
22

33
import static org.junit.Assert.assertNotNull;
4-
import static org.junit.Assert.assertNotSame;
4+
import static org.junit.Assert.assertNull;
55
import static org.junit.Assert.assertSame;
6-
import static org.junit.Assert.fail;
76

87
import java.io.ByteArrayOutputStream;
98
import java.io.IOException;
109
import java.io.InputStream;
1110
import java.net.URL;
1211
import java.util.Enumeration;
1312
import java.util.LinkedHashSet;
14-
import java.util.NoSuchElementException;
1513

1614
import javax.persistence.Entity;
1715

@@ -21,7 +19,6 @@
2119
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
2220
import org.hibernate.integrator.spi.Integrator;
2321
import org.hibernate.internal.util.ConfigHelper;
24-
import org.hibernate.internal.util.ReflectHelper;
2522
import org.hibernate.service.ServiceRegistry;
2623
import org.hibernate.testing.TestForIssue;
2724
import org.junit.Assert;
@@ -58,6 +55,8 @@ public void testSystemClassLoaderNotOverriding() throws IOException, ClassNotFou
5855
/**
5956
* HHH-8363 discovered multiple leaks within CLS. Most notably, it wasn't getting GC'd due to holding
6057
* references to ServiceLoaders. Ensure that the addition of Stoppable functionality cleans up properly.
58+
*
59+
* TODO: Is there a way to test that the ServiceLoader was actually reset?
6160
*/
6261
@Test
6362
@TestForIssue(jiraKey = "HHH-8363")
@@ -77,11 +76,9 @@ public void testStoppableClassLoaderService() {
7776

7877
StandardServiceRegistryBuilder.destroy( serviceRegistry );
7978

79+
// Should return null -- aggregratedClassLoader blown away.
8080
testIntegrator2 = findTestIntegrator( classLoaderService );
81-
assertNotNull( testIntegrator2 );
82-
83-
// destroy should have cleared the ServiceLoader caches, forcing the services to be re-created when called upon
84-
assertNotSame( testIntegrator1, testIntegrator2 );
81+
assertNull( testIntegrator2 );
8582
}
8683

8784
private TestIntegrator findTestIntegrator(ClassLoaderService classLoaderService) {

hibernate-core/src/test/java/org/hibernate/test/service/TestIntegrator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ public class TestIntegrator implements Integrator {
3434
@Override
3535
public void integrate(Configuration configuration, SessionFactoryImplementor sessionFactory,
3636
SessionFactoryServiceRegistry serviceRegistry) {
37-
System.out.println("foo");
37+
3838
}
3939

4040
@Override
4141
public void integrate(MetadataImplementor metadata, SessionFactoryImplementor sessionFactory,
4242
SessionFactoryServiceRegistry serviceRegistry) {
43-
System.out.println("foo");
43+
4444
}
4545

4646
@Override
4747
public void disintegrate(SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
48-
System.out.println("foo");
48+
4949
}
5050

5151
}

hibernate-envers/src/main/java/org/hibernate/envers/configuration/spi/AuditConfiguration.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,13 @@ public synchronized static AuditConfiguration getFor(Configuration cfg, ClassLoa
186186
return verCfg;
187187
}
188188

189-
public void destroy() {
190-
for (Map.Entry<Configuration, AuditConfiguration> c: new HashSet<Map.Entry<Configuration, AuditConfiguration>>(CFGS.entrySet())){
191-
if (c.getValue() == this){//this is nasty cleanup fix, whole static CFGS should be reworked
192-
CFGS.remove(c.getKey());
193-
}
194-
}
195-
classLoaderService = null;
196-
}
189+
public void destroy() {
190+
for ( Map.Entry<Configuration, AuditConfiguration> c : new HashSet<Map.Entry<Configuration, AuditConfiguration>>(
191+
CFGS.entrySet() ) ) {
192+
if ( c.getValue() == this ) { // this is nasty cleanup fix, whole static CFGS should be reworked
193+
CFGS.remove( c.getKey() );
194+
}
195+
}
196+
classLoaderService = null;
197+
}
197198
}

0 commit comments

Comments
 (0)