HHH-16515 - Add o.h.exception to nullness checking

HHH-16515 - Add o.h.integrator to nullness checking

HHH-16515 - Add o.h.service to nullness checking

HHH-16515 - Add o.h.engine.jndi to nullness checking

HHH-16515 - Add o.h.engine.config to nullness checking

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2023-06-09 21:57:34 +02:00 committed by Jan Schatteman
parent 16dc63d555
commit 2e73795e4b
44 changed files with 249 additions and 149 deletions

View File

@ -544,7 +544,7 @@ checkerFramework {
extraJavacArgs = [ extraJavacArgs = [
'-AsuppressWarnings=initialization', '-AsuppressWarnings=initialization',
// stubs is passed directly through options.compilerArgumentProviders // stubs is passed directly through options.compilerArgumentProviders
'-AonlyDefs=^org\\.hibernate\\.(jpamodelgen|spi|pretty|stat|engine\\.(profile|transaction)|(action|context|bytecode)\\.spi)\\.' '-AonlyDefs=^org\\.hibernate\\.(exception|integrator|jpamodelgen|service|spi|pretty|stat|engine\\.(config|jndi|profile|transaction)|(action|context|bytecode)\\.spi)\\.'
] ]
} }

View File

@ -659,10 +659,6 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
this.sharedCacheMode = configService.getSetting( this.sharedCacheMode = configService.getSetting(
AvailableSettings.JAKARTA_SHARED_CACHE_MODE, AvailableSettings.JAKARTA_SHARED_CACHE_MODE,
value -> { value -> {
if ( value == null ) {
return null;
}
if ( value instanceof SharedCacheMode ) { if ( value instanceof SharedCacheMode ) {
return (SharedCacheMode) value; return (SharedCacheMode) value;
} }

View File

@ -187,7 +187,7 @@ public class BootstrapServiceRegistryBuilder {
classLoaderService = providedClassLoaderService; classLoaderService = providedClassLoaderService;
} }
final IntegratorServiceImpl integratorService = new IntegratorServiceImpl( final IntegratorServiceImpl integratorService = IntegratorServiceImpl.create(
providedIntegrators, providedIntegrators,
classLoaderService classLoaderService
); );

View File

@ -365,7 +365,7 @@ public class StandardServiceRegistryBuilder {
settingsCopy.put( LOADED_CONFIG_KEY, aggregatedCfgXml ); settingsCopy.put( LOADED_CONFIG_KEY, aggregatedCfgXml );
ConfigurationHelper.resolvePlaceHolders( settingsCopy ); ConfigurationHelper.resolvePlaceHolders( settingsCopy );
return new StandardServiceRegistryImpl( return StandardServiceRegistryImpl.create(
autoCloseRegistry, autoCloseRegistry,
bootstrapServiceRegistry, bootstrapServiceRegistry,
initiators, initiators,

View File

@ -29,6 +29,8 @@ import org.hibernate.service.spi.ServiceInitiator;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.Stoppable; import org.hibernate.service.spi.Stoppable;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* {@link ServiceRegistry} implementation containing specialized "bootstrap" services, specifically:<ul> * {@link ServiceRegistry} implementation containing specialized "bootstrap" services, specifically:<ul>
* <li>{@link ClassLoaderService}</li> * <li>{@link ClassLoaderService}</li>
@ -117,7 +119,7 @@ public class BootstrapServiceRegistryImpl
this.integratorServiceBinding = new ServiceBinding<>( this.integratorServiceBinding = new ServiceBinding<>(
this, this,
IntegratorService.class, IntegratorService.class,
new IntegratorServiceImpl( providedIntegrators, classLoaderService ) IntegratorServiceImpl.create( providedIntegrators, classLoaderService )
); );
} }
@ -185,7 +187,7 @@ public class BootstrapServiceRegistryImpl
@Override @Override
public <R extends Service> R getService(Class<R> serviceRole) { public <R extends Service> @Nullable R getService(Class<R> serviceRole) {
final ServiceBinding<R> binding = locateServiceBinding( serviceRole ); final ServiceBinding<R> binding = locateServiceBinding( serviceRole );
return binding == null ? null : binding.getService(); return binding == null ? null : binding.getService();
} }
@ -235,7 +237,7 @@ public class BootstrapServiceRegistryImpl
} }
@Override @Override
public ServiceRegistry getParentServiceRegistry() { public @Nullable ServiceRegistry getParentServiceRegistry() {
return null; return null;
} }

View File

@ -30,6 +30,14 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
//Access to this field requires synchronization on -this- //Access to this field requires synchronization on -this-
private Map<String,Object> configurationValues; private Map<String,Object> configurationValues;
protected StandardServiceRegistryImpl(
boolean autoCloseRegistry,
BootstrapServiceRegistry bootstrapServiceRegistry,
Map<String,Object> configurationValues) {
super( bootstrapServiceRegistry, autoCloseRegistry );
this.configurationValues = configurationValues;
}
/** /**
* Constructs a StandardServiceRegistryImpl. Should not be instantiated directly; use * Constructs a StandardServiceRegistryImpl. Should not be instantiated directly; use
* {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder} instead * {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder} instead
@ -41,12 +49,13 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
* *
* @see org.hibernate.boot.registry.StandardServiceRegistryBuilder * @see org.hibernate.boot.registry.StandardServiceRegistryBuilder
*/ */
public StandardServiceRegistryImpl( public static StandardServiceRegistryImpl create(
BootstrapServiceRegistry bootstrapServiceRegistry, BootstrapServiceRegistry bootstrapServiceRegistry,
List<StandardServiceInitiator<?>> serviceInitiators, List<StandardServiceInitiator<?>> serviceInitiators,
List<ProvidedService<?>> providedServices, List<ProvidedService<?>> providedServices,
Map<String,Object> configurationValues) { Map<String,Object> configurationValues) {
this( true, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
return create( true, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
} }
/** /**
@ -62,20 +71,21 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
* *
* @see org.hibernate.boot.registry.StandardServiceRegistryBuilder * @see org.hibernate.boot.registry.StandardServiceRegistryBuilder
*/ */
public StandardServiceRegistryImpl( public static StandardServiceRegistryImpl create(
boolean autoCloseRegistry, boolean autoCloseRegistry,
BootstrapServiceRegistry bootstrapServiceRegistry, BootstrapServiceRegistry bootstrapServiceRegistry,
List<StandardServiceInitiator<?>> serviceInitiators, List<StandardServiceInitiator<?>> serviceInitiators,
List<ProvidedService<?>> providedServices, List<ProvidedService<?>> providedServices,
Map<String,Object> configurationValues) { Map<String,Object> configurationValues) {
super( bootstrapServiceRegistry, autoCloseRegistry );
this.configurationValues = configurationValues; StandardServiceRegistryImpl instance = new StandardServiceRegistryImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
instance.initialize();
instance.applyServiceRegistrations( serviceInitiators, providedServices );
applyServiceRegistrations( serviceInitiators, providedServices ); return instance;
} }
private void applyServiceRegistrations(List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) { protected void applyServiceRegistrations(List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) {
try { try {
// process initiators // process initiators
for ( ServiceInitiator<?> initiator : serviceInitiators ) { for ( ServiceInitiator<?> initiator : serviceInitiators ) {

View File

@ -8,6 +8,8 @@ package org.hibernate.cache.spi.access;
import java.util.Locale; import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Enumerates the policies for managing concurrent access to the shared * Enumerates the policies for managing concurrent access to the shared
* second-level cache. * second-level cache.
@ -70,7 +72,7 @@ public enum AccessType {
* *
* @see #getExternalName() * @see #getExternalName()
*/ */
public static AccessType fromExternalName(String externalName) { public static AccessType fromExternalName(@Nullable String externalName) {
if ( externalName == null ) { if ( externalName == null ) {
return null; return null;
} }

View File

@ -13,11 +13,15 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.spi.ServiceRegistryAwareService; import org.hibernate.service.spi.ServiceRegistryAwareService;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;
/** /**
* The standard {@link ConfigurationService} implementation. * The standard {@link ConfigurationService} implementation.
* *
@ -52,12 +56,12 @@ public class ConfigurationServiceImpl implements ConfigurationService, ServiceRe
} }
@Override @Override
public <T> T getSetting(String name, Converter<T> converter) { public <T> @Nullable T getSetting(String name, Converter<T> converter) {
return getSetting( name, converter, null ); return getSetting( name, converter, null );
} }
@Override @Override
public <T> T getSetting(String name, Converter<T> converter, T defaultValue) { public <T> @PolyNull T getSetting(String name, Converter<T> converter, @PolyNull T defaultValue) {
final Object value = settings.get( name ); final Object value = settings.get( name );
if ( value == null ) { if ( value == null ) {
return defaultValue; return defaultValue;
@ -67,14 +71,14 @@ public class ConfigurationServiceImpl implements ConfigurationService, ServiceRe
} }
@Override @Override
public <T> T getSetting(String name, Class<T> expected, T defaultValue) { public <T> @PolyNull T getSetting(String name, Class<T> expected, @PolyNull T defaultValue) {
final Object value = settings.get( name ); final Object value = settings.get( name );
final T target = cast( expected, value ); final T target = cast( expected, value );
return target !=null ? target : defaultValue; return target !=null ? target : defaultValue;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> T cast(Class<T> expected, Object candidate){ public <T> @Nullable T cast(Class<T> expected, @Nullable Object candidate){
if (candidate == null) { if (candidate == null) {
return null; return null;
} }
@ -89,7 +93,7 @@ public class ConfigurationServiceImpl implements ConfigurationService, ServiceRe
} }
else { else {
try { try {
target = serviceRegistry.getService( ClassLoaderService.class ).classForName( candidate.toString() ); target = NullnessUtil.castNonNull( serviceRegistry.getService( ClassLoaderService.class ) ).classForName( candidate.toString() );
} }
catch ( ClassLoadingException e ) { catch ( ClassLoadingException e ) {
LOG.debugf( "Unable to locate %s implementation class %s", expected.getName(), candidate.toString() ); LOG.debugf( "Unable to locate %s implementation class %s", expected.getName(), candidate.toString() );

View File

@ -10,6 +10,10 @@ import java.util.Map;
import org.hibernate.service.Service; import org.hibernate.service.Service;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;
/** /**
* Provides access to the initial user-provided configuration values. Generally speaking * Provides access to the initial user-provided configuration values. Generally speaking
* these values come from:<ul> * these values come from:<ul>
@ -38,7 +42,7 @@ public interface ConfigurationService extends Service {
* *
* @return The converted (typed) setting. May return {@code null} (see {@link #getSetting(String, Class, Object)}) * @return The converted (typed) setting. May return {@code null} (see {@link #getSetting(String, Class, Object)})
*/ */
<T> T getSetting(String name, Converter<T> converter); <T> @Nullable T getSetting(String name, Converter<T> converter);
/** /**
* Get the named setting, using the specified converter and default value. * Get the named setting, using the specified converter and default value.
@ -50,7 +54,7 @@ public interface ConfigurationService extends Service {
* *
* @return The converted (typed) setting. Will be the defaultValue if no such setting was defined. * @return The converted (typed) setting. Will be the defaultValue if no such setting was defined.
*/ */
<T> T getSetting(String name, Converter<T> converter, T defaultValue); <T> @PolyNull T getSetting(String name, Converter<T> converter, @PolyNull T defaultValue);
/** /**
* Get the named setting. Differs from the form taking a Converter in that here we expect to have a simple * Get the named setting. Differs from the form taking a Converter in that here we expect to have a simple
@ -63,7 +67,7 @@ public interface ConfigurationService extends Service {
* *
* @return The converted (typed) setting. Will be the defaultValue if no such setting was defined. * @return The converted (typed) setting. Will be the defaultValue if no such setting was defined.
*/ */
<T> T getSetting(String name, Class<T> expected, T defaultValue); <T> @PolyNull T getSetting(String name, Class<T> expected, @PolyNull T defaultValue);
/** /**
* Simple conversion contract for converting an untyped object to a specified type. * Simple conversion contract for converting an untyped object to a specified type.
@ -78,6 +82,6 @@ public interface ConfigurationService extends Service {
* *
* @return The converted (typed) value. * @return The converted (typed) value.
*/ */
T convert(Object value); @NonNull T convert(Object value);
} }
} }

View File

@ -7,6 +7,8 @@
package org.hibernate.engine.config.spi; package org.hibernate.engine.config.spi;
import org.checkerframework.checker.nullness.qual.PolyNull;
import static org.hibernate.engine.config.spi.ConfigurationService.Converter; import static org.hibernate.engine.config.spi.ConfigurationService.Converter;
/** /**
@ -18,10 +20,6 @@ public class StandardConverters {
public static final Converter<Boolean> BOOLEAN = StandardConverters::asBoolean; public static final Converter<Boolean> BOOLEAN = StandardConverters::asBoolean;
public static Boolean asBoolean(Object value) { public static Boolean asBoolean(Object value) {
if ( value == null ) {
throw new IllegalArgumentException( "Null value passed to convert" );
}
return value instanceof Boolean return value instanceof Boolean
? (Boolean) value ? (Boolean) value
: Boolean.parseBoolean( value.toString() ); : Boolean.parseBoolean( value.toString() );
@ -30,20 +28,12 @@ public class StandardConverters {
public static final Converter<String> STRING = StandardConverters::asString; public static final Converter<String> STRING = StandardConverters::asString;
public static String asString(Object value) { public static String asString(Object value) {
if ( value == null ) {
throw new IllegalArgumentException( "Null value passed to convert" );
}
return value.toString(); return value.toString();
} }
public static final Converter<Integer> INTEGER = StandardConverters::asInteger; public static final Converter<Integer> INTEGER = StandardConverters::asInteger;
public static Integer asInteger(Object value) { public static Integer asInteger(Object value) {
if ( value == null ) {
throw new IllegalArgumentException( "Null value passed to convert" );
}
if ( value instanceof Number ) { if ( value instanceof Number ) {
return ( (Number) value ).intValue(); return ( (Number) value ).intValue();
} }

View File

@ -24,6 +24,7 @@ import org.hibernate.engine.jndi.JndiException;
import org.hibernate.engine.jndi.JndiNameException; import org.hibernate.engine.jndi.JndiNameException;
import org.hibernate.engine.jndi.spi.JndiService; import org.hibernate.engine.jndi.spi.JndiService;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.NullnessUtil;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -80,7 +81,7 @@ final class JndiServiceImpl implements JndiService {
} }
else { else {
final String passThruPropertyName = propertyName.substring( Environment.JNDI_PREFIX.length() + 1 ); final String passThruPropertyName = propertyName.substring( Environment.JNDI_PREFIX.length() + 1 );
jndiProperties.put( passThruPropertyName, propertyValue ); jndiProperties.put( passThruPropertyName, NullnessUtil.castNonNull( propertyValue ) );
} }
} }
} }

View File

@ -18,6 +18,7 @@ import org.hibernate.engine.jndi.spi.JndiService;
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper; import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.Configurable;
@ -63,7 +64,7 @@ public abstract class AbstractJtaPlatform
} }
protected JndiService jndiService() { protected JndiService jndiService() {
return serviceRegistry().getService( JndiService.class ); return NullnessUtil.castNonNull( serviceRegistry().getService( JndiService.class ) );
} }
protected abstract TransactionManager locateTransactionManager(); protected abstract TransactionManager locateTransactionManager();

View File

@ -11,6 +11,7 @@ import jakarta.transaction.UserTransaction;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
import org.hibernate.internal.util.NullnessUtil;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
@ -21,7 +22,7 @@ public class AtomikosJtaPlatform extends AbstractJtaPlatform {
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {
Class transactionManagerClass = serviceRegistry().getService( ClassLoaderService.class ).classForName( TM_CLASS_NAME ); Class transactionManagerClass = NullnessUtil.castNonNull( serviceRegistry().getService( ClassLoaderService.class ) ).classForName( TM_CLASS_NAME );
return (TransactionManager) transactionManagerClass.newInstance(); return (TransactionManager) transactionManagerClass.newInstance();
} }
catch (Exception e) { catch (Exception e) {

View File

@ -12,6 +12,7 @@ import jakarta.transaction.UserTransaction;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
import org.hibernate.internal.util.NullnessUtil;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
@ -22,7 +23,7 @@ public class BitronixJtaPlatform extends AbstractJtaPlatform {
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {
Class transactionManagerServicesClass = serviceRegistry().getService( ClassLoaderService.class ).classForName( TM_CLASS_NAME ); Class transactionManagerServicesClass = NullnessUtil.castNonNull( serviceRegistry().getService( ClassLoaderService.class ) ).classForName( TM_CLASS_NAME );
final Method getTransactionManagerMethod = transactionManagerServicesClass.getMethod( "getTransactionManager" ); final Method getTransactionManagerMethod = transactionManagerServicesClass.getMethod( "getTransactionManager" );
return (TransactionManager) getTransactionManagerMethod.invoke( null ); return (TransactionManager) getTransactionManagerMethod.invoke( null );
} }

View File

@ -11,6 +11,7 @@ import jakarta.transaction.UserTransaction;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
import org.hibernate.internal.util.NullnessUtil;
/** /**
* Return a standalone JTA transaction manager for JBoss (Arjuna) Transactions or WildFly transaction client * Return a standalone JTA transaction manager for JBoss (Arjuna) Transactions or WildFly transaction client
@ -37,8 +38,8 @@ public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
} }
try { try {
final Class jbossTmClass = serviceRegistry() final Class jbossTmClass = NullnessUtil.castNonNull( serviceRegistry()
.getService( ClassLoaderService.class ) .getService( ClassLoaderService.class ) )
.classForName( JBOSS_TM_CLASS_NAME ); .classForName( JBOSS_TM_CLASS_NAME );
return (TransactionManager) jbossTmClass.getMethod( "transactionManager" ).invoke( null ); return (TransactionManager) jbossTmClass.getMethod( "transactionManager" ).invoke( null );
} }
@ -58,8 +59,8 @@ public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
} }
try { try {
final Class jbossUtClass = serviceRegistry() final Class jbossUtClass = NullnessUtil.castNonNull( serviceRegistry()
.getService( ClassLoaderService.class ) .getService( ClassLoaderService.class ) )
.classForName( JBOSS_UT_CLASS_NAME ); .classForName( JBOSS_UT_CLASS_NAME );
return (UserTransaction) jbossUtClass.getMethod( "userTransaction" ).invoke( null ); return (UserTransaction) jbossUtClass.getMethod( "userTransaction" ).invoke( null );
} }

View File

@ -12,6 +12,7 @@ import jakarta.transaction.UserTransaction;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
import org.hibernate.internal.util.NullnessUtil;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
@ -23,7 +24,7 @@ public class JOTMJtaPlatform extends AbstractJtaPlatform {
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {
final Class tmClass = serviceRegistry().getService( ClassLoaderService.class ).classForName( TM_CLASS_NAME ); final Class tmClass = NullnessUtil.castNonNull( serviceRegistry().getService( ClassLoaderService.class ) ).classForName( TM_CLASS_NAME );
final Method getTransactionManagerMethod = tmClass.getMethod( "getTransactionManager" ); final Method getTransactionManagerMethod = tmClass.getMethod( "getTransactionManager" );
return (TransactionManager) getTransactionManagerMethod.invoke( null, (Object[]) null ); return (TransactionManager) getTransactionManagerMethod.invoke( null, (Object[]) null );
} }

View File

@ -14,6 +14,7 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -38,11 +39,11 @@ public class JtaPlatformInitiator implements StandardServiceInitiator<JtaPlatfor
@Override @Override
public @Nullable JtaPlatform initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry) { public @Nullable JtaPlatform initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry) {
final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM ); final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM );
JtaPlatform platform = registry.getService( StrategySelector.class ).resolveStrategy( JtaPlatform.class, setting ); JtaPlatform platform = NullnessUtil.castNonNull( registry.getService( StrategySelector.class ) ).resolveStrategy( JtaPlatform.class, setting );
if ( platform == null ) { if ( platform == null ) {
LOG.debug( "No JtaPlatform was specified, checking resolver" ); LOG.debug( "No JtaPlatform was specified, checking resolver" );
platform = registry.getService( JtaPlatformResolver.class ).resolveJtaPlatform( configurationValues, registry ); platform = NullnessUtil.castNonNull( registry.getService( JtaPlatformResolver.class ) ).resolveJtaPlatform( configurationValues, registry );
} }
if ( platform == null ) { if ( platform == null ) {

View File

@ -12,6 +12,7 @@ import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -27,7 +28,7 @@ public class JtaPlatformResolverInitiator implements StandardServiceInitiator<Jt
@Override @Override
public JtaPlatformResolver initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry) { public JtaPlatformResolver initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry) {
final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM_RESOLVER ); final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM_RESOLVER );
final JtaPlatformResolver resolver = registry.getService( StrategySelector.class ) final JtaPlatformResolver resolver = NullnessUtil.castNonNull( registry.getService( StrategySelector.class ) )
.resolveStrategy( JtaPlatformResolver.class, setting ); .resolveStrategy( JtaPlatformResolver.class, setting );
if ( resolver == null ) { if ( resolver == null ) {
log.debugf( "No JtaPlatformResolver was specified, using default [%s]", StandardJtaPlatformResolver.class.getName() ); log.debugf( "No JtaPlatformResolver was specified, using default [%s]", StandardJtaPlatformResolver.class.getName() );

View File

@ -13,6 +13,7 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformProvider; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformProvider;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -27,7 +28,7 @@ public class StandardJtaPlatformResolver implements JtaPlatformResolver {
@Override @Override
public JtaPlatform resolveJtaPlatform(Map configurationValues, ServiceRegistryImplementor registry) { public JtaPlatform resolveJtaPlatform(Map configurationValues, ServiceRegistryImplementor registry) {
final ClassLoaderService classLoaderService = registry.getService( ClassLoaderService.class ); final ClassLoaderService classLoaderService = NullnessUtil.castNonNull( registry.getService( ClassLoaderService.class ) );
// Initially look for a JtaPlatformProvider // Initially look for a JtaPlatformProvider
for ( JtaPlatformProvider provider : classLoaderService.loadJavaServices( JtaPlatformProvider.class ) ) { for ( JtaPlatformProvider provider : classLoaderService.loadJavaServices( JtaPlatformProvider.class ) ) {

View File

@ -34,8 +34,8 @@ public class WebSphereLibertyJtaPlatform extends AbstractJtaPlatform {
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {
final Class<?> TransactionManagerFactory = serviceRegistry() final Class<?> TransactionManagerFactory = NullnessUtil.castNonNull( serviceRegistry()
.getService( ClassLoaderService.class ) .getService( ClassLoaderService.class ) )
.classForName( TMF_CLASS_NAME ); .classForName( TMF_CLASS_NAME );
return (TransactionManager) TransactionManagerFactory.getMethod("getTransactionManager").invoke(null); return (TransactionManager) TransactionManagerFactory.getMethod("getTransactionManager").invoke(null);
} }

View File

@ -11,6 +11,7 @@ import jakarta.transaction.UserTransaction;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
import org.hibernate.internal.util.NullnessUtil;
/** /**
* Return a standalone JTA transaction manager for WildFly transaction client * Return a standalone JTA transaction manager for WildFly transaction client
@ -25,8 +26,8 @@ public class WildFlyStandAloneJtaPlatform extends AbstractJtaPlatform {
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {
final Class wildflyTmClass = serviceRegistry() final Class wildflyTmClass = NullnessUtil.castNonNull( serviceRegistry()
.getService( ClassLoaderService.class ) .getService( ClassLoaderService.class ) )
.classForName( WILDFLY_TM_CLASS_NAME ); .classForName( WILDFLY_TM_CLASS_NAME );
return (TransactionManager) wildflyTmClass.getMethod( "getInstance" ).invoke( null ); return (TransactionManager) wildflyTmClass.getMethod( "getInstance" ).invoke( null );
} }
@ -41,8 +42,8 @@ public class WildFlyStandAloneJtaPlatform extends AbstractJtaPlatform {
@Override @Override
protected UserTransaction locateUserTransaction() { protected UserTransaction locateUserTransaction() {
try { try {
final Class jbossUtClass = serviceRegistry() final Class jbossUtClass = NullnessUtil.castNonNull( serviceRegistry()
.getService( ClassLoaderService.class ) .getService( ClassLoaderService.class ) )
.classForName( WILDFLY_UT_CLASS_NAME ); .classForName( WILDFLY_UT_CLASS_NAME );
return (UserTransaction) jbossUtClass.getMethod( "getInstance" ).invoke( null ); return (UserTransaction) jbossUtClass.getMethod( "getInstance" ).invoke( null );
} }

View File

@ -9,6 +9,8 @@ import java.sql.SQLException;
import org.hibernate.JDBCException; import org.hibernate.JDBCException;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* A {@link JDBCException} indicating that the requested DML operation * A {@link JDBCException} indicating that the requested DML operation
* resulted in violation of a defined integrity constraint. * resulted in violation of a defined integrity constraint.
@ -17,14 +19,14 @@ import org.hibernate.JDBCException;
*/ */
public class ConstraintViolationException extends JDBCException { public class ConstraintViolationException extends JDBCException {
private final String constraintName; private final @Nullable String constraintName;
public ConstraintViolationException(String message, SQLException root, String constraintName) { public ConstraintViolationException(String message, SQLException root, @Nullable String constraintName) {
super( message, root ); super( message, root );
this.constraintName = constraintName; this.constraintName = constraintName;
} }
public ConstraintViolationException(String message, SQLException root, String sql, String constraintName) { public ConstraintViolationException(String message, SQLException root, String sql, @Nullable String constraintName) {
super( message, root, sql ); super( message, root, sql );
this.constraintName = constraintName; this.constraintName = constraintName;
} }
@ -34,7 +36,7 @@ public class ConstraintViolationException extends JDBCException {
* *
* @return The name of the violated constraint, or null if not known. * @return The name of the violated constraint, or null if not known.
*/ */
public String getConstraintName() { public @Nullable String getConstraintName() {
return constraintName; return constraintName;
} }
} }

View File

@ -28,6 +28,8 @@ import org.hibernate.exception.SQLGrammarException;
import org.hibernate.exception.spi.AbstractSQLExceptionConversionDelegate; import org.hibernate.exception.spi.AbstractSQLExceptionConversionDelegate;
import org.hibernate.exception.spi.ConversionContext; import org.hibernate.exception.spi.ConversionContext;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* A {@link org.hibernate.exception.spi.SQLExceptionConverter} implementation * A {@link org.hibernate.exception.spi.SQLExceptionConverter} implementation
* that does conversion based on the {@link SQLException} subtype hierarchy * that does conversion based on the {@link SQLException} subtype hierarchy
@ -41,7 +43,7 @@ public class SQLExceptionTypeDelegate extends AbstractSQLExceptionConversionDele
} }
@Override @Override
public JDBCException convert(SQLException sqlException, String message, String sql) { public @Nullable JDBCException convert(SQLException sqlException, String message, String sql) {
if ( sqlException instanceof SQLClientInfoException if ( sqlException instanceof SQLClientInfoException
|| sqlException instanceof SQLInvalidAuthorizationSpecException || sqlException instanceof SQLInvalidAuthorizationSpecException
|| sqlException instanceof SQLNonTransientConnectionException || sqlException instanceof SQLNonTransientConnectionException

View File

@ -21,6 +21,8 @@ import org.hibernate.exception.spi.AbstractSQLExceptionConversionDelegate;
import org.hibernate.exception.spi.ConversionContext; import org.hibernate.exception.spi.ConversionContext;
import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.internal.util.JdbcExceptionHelper;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* A {@link org.hibernate.exception.spi.SQLExceptionConverter} implementation which performs conversion based * A {@link org.hibernate.exception.spi.SQLExceptionConverter} implementation which performs conversion based
* on the underlying SQLState. Interpretation of a SQL error based on SQLState is not nearly as accurate as * on the underlying SQLState. Interpretation of a SQL error based on SQLState is not nearly as accurate as
@ -77,7 +79,7 @@ public class SQLStateConversionDelegate extends AbstractSQLExceptionConversionDe
} }
@Override @Override
public JDBCException convert(SQLException sqlException, String message, String sql) { public @Nullable JDBCException convert(SQLException sqlException, String message, String sql) {
final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException ); final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException ); final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );

View File

@ -16,6 +16,8 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* A {@link SQLExceptionConverter} that delegates to a chain of * A {@link SQLExceptionConverter} that delegates to a chain of
* {@link SQLExceptionConversionDelegate}. * {@link SQLExceptionConversionDelegate}.
@ -44,7 +46,7 @@ public class StandardSQLExceptionConverter implements SQLExceptionConverter {
* @deprecated use {@link #StandardSQLExceptionConverter(SQLExceptionConversionDelegate...)} * @deprecated use {@link #StandardSQLExceptionConverter(SQLExceptionConversionDelegate...)}
*/ */
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
public void addDelegate(SQLExceptionConversionDelegate delegate) { public void addDelegate(@Nullable SQLExceptionConversionDelegate delegate) {
if ( delegate != null ) { if ( delegate != null ) {
this.delegates.add( delegate ); this.delegates.add( delegate );
} }

View File

@ -10,6 +10,8 @@ import java.sql.SQLException;
import org.hibernate.JDBCException; import org.hibernate.JDBCException;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Allow a {@link SQLExceptionConverter} to work by chaining together * Allow a {@link SQLExceptionConverter} to work by chaining together
* multiple delegates. The main difference between a delegate and a * multiple delegates. The main difference between a delegate and a
@ -31,6 +33,6 @@ public interface SQLExceptionConversionDelegate {
* if this delegate does not know how to interpret the * if this delegate does not know how to interpret the
* given {@link SQLException}. * given {@link SQLException}.
*/ */
JDBCException convert(SQLException sqlException, String message, String sql); @Nullable JDBCException convert(SQLException sqlException, String message, String sql);
} }

View File

@ -9,6 +9,10 @@ package org.hibernate.exception.spi;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.function.Function; import java.util.function.Function;
import org.hibernate.internal.util.NullnessUtil;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Extracts a violated database constraint name from an error message * Extracts a violated database constraint name from an error message
* by matching the error message against a template. * by matching the error message against a template.
@ -25,7 +29,7 @@ public class TemplatedViolatedConstraintNameExtractor implements ViolatedConstra
} }
@Override @Override
public String extractConstraintName(SQLException sqle) { public @Nullable String extractConstraintName(SQLException sqle) {
try { try {
String constraintName = null; String constraintName = null;
@ -37,7 +41,7 @@ public class TemplatedViolatedConstraintNameExtractor implements ViolatedConstra
break; break;
} }
else { else {
sqle = sqle.getNextException(); sqle = NullnessUtil.castNonNull( sqle.getNextException() );
} }
} while (constraintName == null); } while (constraintName == null);
@ -57,7 +61,7 @@ public class TemplatedViolatedConstraintNameExtractor implements ViolatedConstra
* @param message The templated error message containing the constraint name. * @param message The templated error message containing the constraint name.
* @return The found constraint name, or null. * @return The found constraint name, or null.
*/ */
public static String extractUsingTemplate(String templateStart, String templateEnd, String message) { public static @Nullable String extractUsingTemplate(String templateStart, String templateEnd, String message) {
int templateStartPosition = message.indexOf( templateStart ); int templateStartPosition = message.indexOf( templateStart );
if ( templateStartPosition < 0 ) { if ( templateStartPosition < 0 ) {
return null; return null;

View File

@ -8,6 +8,8 @@ package org.hibernate.exception.spi;
import java.sql.SQLException; import java.sql.SQLException;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* An object that can extract the name of a violated database constraint * An object that can extract the name of a violated database constraint
* from a {@link SQLException} that results from the constraint violation. * from a {@link SQLException} that results from the constraint violation.
@ -23,5 +25,5 @@ public interface ViolatedConstraintNameExtractor {
* @param sqle The exception that was the result of the constraint violation. * @param sqle The exception that was the result of the constraint violation.
* @return The extracted constraint name. * @return The extracted constraint name.
*/ */
String extractConstraintName(SQLException sqle); @Nullable String extractConstraintName(SQLException sqle);
} }

View File

@ -8,6 +8,8 @@ package org.hibernate.id;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Describes the strategy for handling the mismatch between a database sequence configuration and * Describes the strategy for handling the mismatch between a database sequence configuration and
* the one defined by the entity mapping. * the one defined by the entity mapping.
@ -53,7 +55,7 @@ public enum SequenceMismatchStrategy {
* *
* @return associated {@link SequenceMismatchStrategy} object * @return associated {@link SequenceMismatchStrategy} object
*/ */
public static SequenceMismatchStrategy interpret(Object sequenceMismatchStrategy) { public static SequenceMismatchStrategy interpret(@Nullable Object sequenceMismatchStrategy) {
if ( sequenceMismatchStrategy == null ) { if ( sequenceMismatchStrategy == null ) {
return EXCEPTION; return EXCEPTION;
} }

View File

@ -24,20 +24,26 @@ public class IntegratorServiceImpl implements IntegratorService {
private final LinkedHashSet<Integrator> integrators = new LinkedHashSet<>(); private final LinkedHashSet<Integrator> integrators = new LinkedHashSet<>();
public IntegratorServiceImpl(LinkedHashSet<Integrator> providedIntegrators, ClassLoaderService classLoaderService) { private IntegratorServiceImpl() {
}
public static IntegratorServiceImpl create(LinkedHashSet<Integrator> providedIntegrators, ClassLoaderService classLoaderService) {
IntegratorServiceImpl instance = new IntegratorServiceImpl();
// register standard integrators. Envers and JPA, for example, need to be handled by discovery because in // register standard integrators. Envers and JPA, for example, need to be handled by discovery because in
// separate project/jars. // separate project/jars.
addIntegrator( new BeanValidationIntegrator() ); instance.addIntegrator( new BeanValidationIntegrator() );
addIntegrator( new CollectionCacheInvalidator() ); instance.addIntegrator( new CollectionCacheInvalidator() );
// register provided integrators // register provided integrators
for ( Integrator integrator : providedIntegrators ) { for ( Integrator integrator : providedIntegrators ) {
addIntegrator( integrator ); instance.addIntegrator( integrator );
}
for ( Integrator integrator : classLoaderService.loadJavaServices( Integrator.class ) ) {
instance.addIntegrator( integrator );
} }
for ( Integrator integrator : classLoaderService.loadJavaServices( Integrator.class ) ) { return instance;
addIntegrator( integrator );
}
} }
private void addIntegrator(Integrator integrator) { private void addIntegrator(Integrator integrator) {

View File

@ -592,10 +592,6 @@ public final class ConfigurationHelper {
@Override @Override
public Integer convert(Object value) { public Integer convert(Object value) {
if ( value == null ) {
throw new IllegalArgumentException( "Null value passed to convert" );
}
if ( value instanceof Number ) { if ( value instanceof Number ) {
return ( (Number) value ).intValue(); return ( (Number) value ).intValue();
} }

View File

@ -6,6 +6,8 @@
*/ */
package org.hibernate.service; package org.hibernate.service;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* A registry of {@linkplain Service services}. This interface abstracts * A registry of {@linkplain Service services}. This interface abstracts
* the operations of: * the operations of:
@ -27,7 +29,7 @@ public interface ServiceRegistry extends AutoCloseable {
* *
* @return The parent registry. May be null. * @return The parent registry. May be null.
*/ */
ServiceRegistry getParentServiceRegistry(); @Nullable ServiceRegistry getParentServiceRegistry();
/** /**
* Retrieve a service by role. If service is not found, but a {@link org.hibernate.service.spi.ServiceInitiator} is * Retrieve a service by role. If service is not found, but a {@link org.hibernate.service.spi.ServiceInitiator} is
@ -42,7 +44,7 @@ public interface ServiceRegistry extends AutoCloseable {
* *
* @throws UnknownServiceException Indicates the service was not known. * @throws UnknownServiceException Indicates the service was not known.
*/ */
<R extends Service> R getService(Class<R> serviceRole); <R extends Service> @Nullable R getService(Class<R> serviceRole);
/** /**
* Retrieve a service by role. If service is not found, but a {@link org.hibernate.service.spi.ServiceInitiator} is * Retrieve a service by role. If service is not found, but a {@link org.hibernate.service.spi.ServiceInitiator} is

View File

@ -35,6 +35,8 @@ import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.Startable; import org.hibernate.service.spi.Startable;
import org.hibernate.service.spi.Stoppable; import org.hibernate.service.spi.Stoppable;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Basic implementation of the {@link ServiceRegistry} and {@link ServiceRegistryImplementor} contracts. * Basic implementation of the {@link ServiceRegistry} and {@link ServiceRegistryImplementor} contracts.
* *
@ -48,7 +50,7 @@ public abstract class AbstractServiceRegistryImpl
public static final String ALLOW_CRAWLING = "hibernate.service.allow_crawling"; public static final String ALLOW_CRAWLING = "hibernate.service.allow_crawling";
private volatile ServiceRegistryImplementor parent; private volatile @Nullable ServiceRegistryImplementor parent;
private final boolean allowCrawling; private final boolean allowCrawling;
private final ConcurrentMap<Class<?>,ServiceBinding<?>> serviceBindingMap = new ConcurrentHashMap<>(); private final ConcurrentMap<Class<?>,ServiceBinding<?>> serviceBindingMap = new ConcurrentHashMap<>();
@ -70,26 +72,17 @@ public abstract class AbstractServiceRegistryImpl
private final AtomicBoolean active = new AtomicBoolean( true ); private final AtomicBoolean active = new AtomicBoolean( true );
protected AbstractServiceRegistryImpl() { protected AbstractServiceRegistryImpl(@Nullable ServiceRegistryImplementor parent) {
this( (ServiceRegistryImplementor) null );
}
protected AbstractServiceRegistryImpl(boolean autoCloseRegistry) {
this( (ServiceRegistryImplementor) null, autoCloseRegistry );
}
protected AbstractServiceRegistryImpl(ServiceRegistryImplementor parent) {
this( parent, true ); this( parent, true );
} }
protected AbstractServiceRegistryImpl( protected AbstractServiceRegistryImpl(
ServiceRegistryImplementor parent, @Nullable ServiceRegistryImplementor parent,
boolean autoCloseRegistry) { boolean autoCloseRegistry) {
this.parent = parent; this.parent = parent;
this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true ); this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true );
this.autoCloseRegistry = autoCloseRegistry; this.autoCloseRegistry = autoCloseRegistry;
this.parent.registerChild( this );
} }
public AbstractServiceRegistryImpl(BootstrapServiceRegistry bootstrapServiceRegistry) { public AbstractServiceRegistryImpl(BootstrapServiceRegistry bootstrapServiceRegistry) {
@ -99,14 +92,20 @@ public abstract class AbstractServiceRegistryImpl
public AbstractServiceRegistryImpl( public AbstractServiceRegistryImpl(
BootstrapServiceRegistry bootstrapServiceRegistry, BootstrapServiceRegistry bootstrapServiceRegistry,
boolean autoCloseRegistry) { boolean autoCloseRegistry) {
if ( !(bootstrapServiceRegistry instanceof ServiceRegistryImplementor) ) { if ( !(bootstrapServiceRegistry instanceof ServiceRegistryImplementor) ) {
throw new IllegalArgumentException( "ServiceRegistry parent needs to implement ServiceRegistryImplementor" ); throw new IllegalArgumentException( "ServiceRegistry parent needs to implement ServiceRegistryImplementor" );
} }
this.parent = (ServiceRegistryImplementor) bootstrapServiceRegistry; this.parent = (ServiceRegistryImplementor) bootstrapServiceRegistry;
this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true ); this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true );
this.autoCloseRegistry = autoCloseRegistry; this.autoCloseRegistry = autoCloseRegistry;
this.parent.registerChild( this ); }
// For nullness checking purposes
protected void initialize() {
if ( this.parent != null ) {
this.parent.registerChild( this );
}
} }
protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) { protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) {
@ -128,17 +127,17 @@ public abstract class AbstractServiceRegistryImpl
} }
@Override @Override
public ServiceRegistry getParentServiceRegistry() { public @Nullable ServiceRegistry getParentServiceRegistry() {
return parent; return parent;
} }
@Override @Override
public <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole) { public <R extends Service> @Nullable ServiceBinding<R> locateServiceBinding(Class<R> serviceRole) {
return locateServiceBinding( serviceRole, true ); return locateServiceBinding( serviceRole, true );
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole, boolean checkParent) { protected <R extends Service> @Nullable ServiceBinding<R> locateServiceBinding(Class<R> serviceRole, boolean checkParent) {
ServiceBinding<R> serviceBinding = (ServiceBinding<R>) serviceBindingMap.get( serviceRole ); ServiceBinding<R> serviceBinding = (ServiceBinding<R>) serviceBindingMap.get( serviceRole );
if ( serviceBinding == null && checkParent && parent != null ) { if ( serviceBinding == null && checkParent && parent != null ) {
// look in parent // look in parent
@ -184,7 +183,7 @@ public abstract class AbstractServiceRegistryImpl
} }
@Override @Override
public <R extends Service> R getService(Class<R> serviceRole) { public <R extends Service> @Nullable R getService(Class<R> serviceRole) {
//Fast-path for ClassLoaderService as it's extremely hot during bootstrap //Fast-path for ClassLoaderService as it's extremely hot during bootstrap
//(and after bootstrap service loading performance is less interesting as it's //(and after bootstrap service loading performance is less interesting as it's
//ideally being cached by long term consumers) //ideally being cached by long term consumers)
@ -230,7 +229,7 @@ public abstract class AbstractServiceRegistryImpl
} }
} }
private <R extends Service> R initializeService(ServiceBinding<R> serviceBinding) { private <R extends Service> @Nullable R initializeService(ServiceBinding<R> serviceBinding) {
if ( log.isTraceEnabled() ) { if ( log.isTraceEnabled() ) {
log.tracev( "Initializing service [role={0}]", serviceBinding.getServiceRole().getName() ); log.tracev( "Initializing service [role={0}]", serviceBinding.getServiceRole().getName() );
} }
@ -253,7 +252,7 @@ public abstract class AbstractServiceRegistryImpl
return service; return service;
} }
protected <R extends Service> R createService(ServiceBinding<R> serviceBinding) { protected <R extends Service> @Nullable R createService(ServiceBinding<R> serviceBinding) {
final ServiceInitiator<R> serviceInitiator = serviceBinding.getServiceInitiator(); final ServiceInitiator<R> serviceInitiator = serviceBinding.getServiceInitiator();
if ( serviceInitiator == null ) { if ( serviceInitiator == null ) {
// this condition should never ever occur // this condition should never ever occur
@ -371,7 +370,9 @@ public abstract class AbstractServiceRegistryImpl
serviceBindingMap.clear(); serviceBindingMap.clear();
} }
finally { finally {
parent.deRegisterChild( this ); if ( parent != null ) {
parent.deRegisterChild( this );
}
} }
} }
} }
@ -429,7 +430,7 @@ public abstract class AbstractServiceRegistryImpl
* Not intended for general use. We need the ability to stop and "reactivate" a registry to allow * Not intended for general use. We need the ability to stop and "reactivate" a registry to allow
* experimentation with technologies such as GraalVM, Quarkus and Cri-O. * experimentation with technologies such as GraalVM, Quarkus and Cri-O.
*/ */
public synchronized void resetParent(BootstrapServiceRegistry newParent) { public synchronized void resetParent(@Nullable BootstrapServiceRegistry newParent) {
if ( this.parent != null ) { if ( this.parent != null ) {
this.parent.deRegisterChild( this ); this.parent.deRegisterChild( this );
} }
@ -446,14 +447,14 @@ public abstract class AbstractServiceRegistryImpl
} }
@Override @Override
public <T extends Service> T fromRegistryOrChildren(Class<T> serviceRole) { public <T extends Service> @Nullable T fromRegistryOrChildren(Class<T> serviceRole) {
return fromRegistryOrChildren( serviceRole, this, childRegistries ); return fromRegistryOrChildren( serviceRole, this, childRegistries );
} }
public static <T extends Service> T fromRegistryOrChildren( public static <T extends Service> @Nullable T fromRegistryOrChildren(
Class<T> serviceRole, Class<T> serviceRole,
ServiceRegistryImplementor serviceRegistry, ServiceRegistryImplementor serviceRegistry,
Set<ServiceRegistryImplementor> childRegistries) { @Nullable Set<ServiceRegistryImplementor> childRegistries) {
// prefer `serviceRegistry` // prefer `serviceRegistry`
final T localService = serviceRegistry.getService( serviceRole ); final T localService = serviceRegistry.getService( serviceRole );
if ( localService != null ) { if ( localService != null ) {

View File

@ -60,7 +60,7 @@ public class SessionFactoryServiceRegistryBuilderImpl implements SessionFactoryS
public SessionFactoryServiceRegistry buildSessionFactoryServiceRegistry( public SessionFactoryServiceRegistry buildSessionFactoryServiceRegistry(
SessionFactoryImplementor sessionFactory, SessionFactoryImplementor sessionFactory,
SessionFactoryOptions options) { SessionFactoryOptions options) {
return new SessionFactoryServiceRegistryImpl( return SessionFactoryServiceRegistryImpl.create(
parent, parent,
initiators, initiators,
providedServices, providedServices,

View File

@ -9,6 +9,7 @@ package org.hibernate.service.internal;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceContributor; import org.hibernate.service.spi.SessionFactoryServiceContributor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry; import org.hibernate.service.spi.SessionFactoryServiceRegistry;
@ -31,7 +32,7 @@ public class SessionFactoryServiceRegistryFactoryImpl implements SessionFactoryS
public SessionFactoryServiceRegistry buildServiceRegistry( public SessionFactoryServiceRegistry buildServiceRegistry(
SessionFactoryImplementor sessionFactory, SessionFactoryImplementor sessionFactory,
SessionFactoryOptions options) { SessionFactoryOptions options) {
final ClassLoaderService cls = options.getServiceRegistry().getService( ClassLoaderService.class ); final ClassLoaderService cls = NullnessUtil.castNonNull( options.getServiceRegistry().getService( ClassLoaderService.class ) );
final SessionFactoryServiceRegistryBuilderImpl builder = new SessionFactoryServiceRegistryBuilderImpl( theBasicServiceRegistry ); final SessionFactoryServiceRegistryBuilderImpl builder = new SessionFactoryServiceRegistryBuilderImpl( theBasicServiceRegistry );
for ( SessionFactoryServiceContributor contributor : cls.loadJavaServices( SessionFactoryServiceContributor.class ) ) { for ( SessionFactoryServiceContributor contributor : cls.loadJavaServices( SessionFactoryServiceContributor.class ) ) {

View File

@ -12,6 +12,7 @@ import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.Service; import org.hibernate.service.Service;
import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.ServiceBinding; import org.hibernate.service.spi.ServiceBinding;
@ -23,6 +24,8 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@ -35,17 +38,28 @@ public class SessionFactoryServiceRegistryImpl
private final SessionFactoryOptions sessionFactoryOptions; private final SessionFactoryOptions sessionFactoryOptions;
private final SessionFactoryImplementor sessionFactory; private final SessionFactoryImplementor sessionFactory;
public SessionFactoryServiceRegistryImpl( private SessionFactoryServiceRegistryImpl(
ServiceRegistryImplementor parent,
SessionFactoryImplementor sessionFactory,
SessionFactoryOptions sessionFactoryOptions) {
super( parent );
this.sessionFactory = sessionFactory;
this.sessionFactoryOptions = sessionFactoryOptions;
}
public static SessionFactoryServiceRegistryImpl create(
ServiceRegistryImplementor parent, ServiceRegistryImplementor parent,
List<SessionFactoryServiceInitiator<?>> initiators, List<SessionFactoryServiceInitiator<?>> initiators,
List<ProvidedService<?>> providedServices, List<ProvidedService<?>> providedServices,
SessionFactoryImplementor sessionFactory, SessionFactoryImplementor sessionFactory,
SessionFactoryOptions sessionFactoryOptions) { SessionFactoryOptions sessionFactoryOptions) {
super( parent ); SessionFactoryServiceRegistryImpl instance = new SessionFactoryServiceRegistryImpl( parent, sessionFactory, sessionFactoryOptions);
instance.initialize( initiators, providedServices );
this.sessionFactory = sessionFactory; return instance;
this.sessionFactoryOptions = sessionFactoryOptions; }
protected void initialize(List<SessionFactoryServiceInitiator<?>> initiators, List<ProvidedService<?>> providedServices) {
super.initialize();
// for now, just use the standard initiator list // for now, just use the standard initiator list
for ( SessionFactoryServiceInitiator<?> initiator : initiators ) { for ( SessionFactoryServiceInitiator<?> initiator : initiators ) {
// create the bindings up front to help identify to which registry services belong // create the bindings up front to help identify to which registry services belong
@ -66,7 +80,7 @@ public class SessionFactoryServiceRegistryImpl
@Override @Override
public <R extends Service> void configureService(ServiceBinding<R> serviceBinding) { public <R extends Service> void configureService(ServiceBinding<R> serviceBinding) {
if ( serviceBinding.getService() instanceof Configurable ) { if ( serviceBinding.getService() instanceof Configurable ) {
( (Configurable) serviceBinding.getService() ).configure( getService( ConfigurationService.class ).getSettings() ); ( (Configurable) serviceBinding.getService() ).configure( NullnessUtil.castNonNull( getService( ConfigurationService.class ) ).getSettings() );
} }
} }
@ -86,7 +100,7 @@ public class SessionFactoryServiceRegistryImpl
} }
@Override @Override
public <R extends Service> R getService(Class<R> serviceRole) { public <R extends Service> @Nullable R getService(Class<R> serviceRole) {
if ( serviceRole.equals( EventListenerRegistry.class ) ) { if ( serviceRole.equals( EventListenerRegistry.class ) ) {
log.debug( log.debug(
"EventListenerRegistry access via ServiceRegistry is deprecated. " + "EventListenerRegistry access via ServiceRegistry is deprecated. " +

View File

@ -10,6 +10,8 @@ import org.hibernate.service.Service;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Models a binding for a particular service. * Models a binding for a particular service.
* *
@ -30,7 +32,7 @@ public final class ServiceBinding<R extends Service> {
private final ServiceLifecycleOwner lifecycleOwner; private final ServiceLifecycleOwner lifecycleOwner;
private final Class<R> serviceRole; private final Class<R> serviceRole;
private final ServiceInitiator<R> serviceInitiator; private final @Nullable ServiceInitiator<R> serviceInitiator;
private volatile R service; private volatile R service;
public ServiceBinding(ServiceLifecycleOwner lifecycleOwner, Class<R> serviceRole, R service) { public ServiceBinding(ServiceLifecycleOwner lifecycleOwner, Class<R> serviceRole, R service) {
@ -54,7 +56,7 @@ public final class ServiceBinding<R extends Service> {
return serviceRole; return serviceRole;
} }
public ServiceInitiator<R> getServiceInitiator() { public @Nullable ServiceInitiator<R> getServiceInitiator() {
return serviceInitiator; return serviceInitiator;
} }

View File

@ -9,6 +9,8 @@ package org.hibernate.service.spi;
import org.hibernate.service.Service; import org.hibernate.service.Service;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Additional integration contracts for a service registry. * Additional integration contracts for a service registry.
* *
@ -23,7 +25,7 @@ public interface ServiceRegistryImplementor extends ServiceRegistry {
* *
* @return The located binding; may be {@code null} * @return The located binding; may be {@code null}
*/ */
<R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole); <R extends Service> @Nullable ServiceBinding<R> locateServiceBinding(Class<R> serviceRole);
@Override @Override
default void close() { default void close() {
@ -47,5 +49,5 @@ public interface ServiceRegistryImplementor extends ServiceRegistry {
*/ */
void deRegisterChild(ServiceRegistryImplementor child); void deRegisterChild(ServiceRegistryImplementor child);
<T extends Service> T fromRegistryOrChildren(Class<T> serviceRole); <T extends Service> @Nullable T fromRegistryOrChildren(Class<T> serviceRole);
} }

View File

@ -11,6 +11,7 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceInitiator; import org.hibernate.service.spi.SessionFactoryServiceInitiator;
import org.hibernate.service.spi.SessionFactoryServiceInitiatorContext; import org.hibernate.service.spi.SessionFactoryServiceInitiatorContext;
@ -42,8 +43,8 @@ public class StatisticsInitiator implements SessionFactoryServiceInitiator<Stati
@Override @Override
public StatisticsImplementor initiateService(SessionFactoryServiceInitiatorContext context) { public StatisticsImplementor initiateService(SessionFactoryServiceInitiatorContext context) {
final Object configValue = context.getServiceRegistry() final Object configValue = NullnessUtil.castNonNull( context.getServiceRegistry()
.getService( ConfigurationService.class ) .getService( ConfigurationService.class ) )
.getSettings() .getSettings()
.get( STATS_BUILDER ); .get( STATS_BUILDER );
return initiateServiceInternal( context.getSessionFactory(), configValue, context.getServiceRegistry() ); return initiateServiceInternal( context.getSessionFactory(), configValue, context.getServiceRegistry() );
@ -63,7 +64,7 @@ public class StatisticsInitiator implements SessionFactoryServiceInitiator<Stati
} }
else { else {
// assume it names the factory class // assume it names the factory class
final ClassLoaderService classLoaderService = registry.getService( ClassLoaderService.class ); final ClassLoaderService classLoaderService = NullnessUtil.castNonNull( registry.getService( ClassLoaderService.class ) );
try { try {
statisticsFactory = (StatisticsFactory) classLoaderService.classForName( configValue.toString() ).newInstance(); statisticsFactory = (StatisticsFactory) classLoaderService.classForName( configValue.toString() ).newInstance();
} }

View File

@ -12,6 +12,8 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.type.descriptor.java.ByteArrayJavaType; import org.hibernate.type.descriptor.java.ByteArrayJavaType;
import org.hibernate.type.descriptor.java.CharacterArrayJavaType; import org.hibernate.type.descriptor.java.CharacterArrayJavaType;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Possible options for how to handle {@code Byte[]} and {@code Character[]} basic mappings * Possible options for how to handle {@code Byte[]} and {@code Character[]} basic mappings
* encountered in the application domain model. * encountered in the application domain model.
@ -70,7 +72,7 @@ public enum WrapperArrayHandling {
* Form of {@link #interpretExternalSetting(Object)} which allows incoming {@code null} values and * Form of {@link #interpretExternalSetting(Object)} which allows incoming {@code null} values and
* simply returns {@code null}. Useful for chained resolutions * simply returns {@code null}. Useful for chained resolutions
*/ */
public static WrapperArrayHandling interpretExternalSettingLeniently(Object value) { public static WrapperArrayHandling interpretExternalSettingLeniently(@Nullable Object value) {
if ( value == null ) { if ( value == null ) {
return null; return null;
} }

View File

@ -9,8 +9,11 @@ package org.hibernate.orm.test.connection;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Driver; import java.sql.Driver;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.StandardServiceInitiator; import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl; import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
@ -20,9 +23,9 @@ import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.exception.JDBCConnectionException; import org.hibernate.exception.JDBCConnectionException;
import org.hibernate.service.Service; import org.hibernate.service.Service;
import org.hibernate.service.internal.ProvidedService; import org.hibernate.service.internal.ProvidedService;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -32,27 +35,17 @@ import static org.junit.Assert.fail;
*/ */
public class ConnectionCreatorTest extends BaseUnitTestCase { public class ConnectionCreatorTest extends BaseUnitTestCase {
@Test @Test
@TestForIssue( jiraKey = "HHH-8621" ) @JiraKey(value = "HHH-8621" )
public void testBadUrl() throws Exception { public void testBadUrl() throws Exception {
DriverConnectionCreator connectionCreator = new DriverConnectionCreator( DriverConnectionCreator connectionCreator = new DriverConnectionCreator(
(Driver) Class.forName( "org.h2.Driver" ).newInstance(), (Driver) Class.forName( "org.h2.Driver" ).newInstance(),
new StandardServiceRegistryImpl( CCTStandardServiceRegistryImpl.create(
true, true,
new BootstrapServiceRegistryImpl(), new BootstrapServiceRegistryImpl(),
Collections.emptyList(), Collections.emptyList(),
Collections.emptyList(), Collections.emptyList(),
Collections.emptyMap() Collections.emptyMap()
) { ),
@Override
@SuppressWarnings("unchecked")
public <R extends Service> R getService(Class<R> serviceRole) {
if ( JdbcServices.class.equals( serviceRole ) ) {
// return a new, not fully initialized JdbcServicesImpl
return (R) new JdbcServicesImpl();
}
return super.getService( serviceRole );
}
},
"jdbc:h2:mem:test-bad-urls;nosuchparam=saywhat", "jdbc:h2:mem:test-bad-urls;nosuchparam=saywhat",
new Properties(), new Properties(),
false, false,
@ -68,4 +61,37 @@ public class ConnectionCreatorTest extends BaseUnitTestCase {
catch (JDBCConnectionException expected) { catch (JDBCConnectionException expected) {
} }
} }
private final static class CCTStandardServiceRegistryImpl extends StandardServiceRegistryImpl {
private CCTStandardServiceRegistryImpl(
boolean autoCloseRegistry,
BootstrapServiceRegistry bootstrapServiceRegistry,
Map<String, Object> configurationValues) {
super( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
}
@Override
@SuppressWarnings("unchecked")
public <R extends Service> R getService(Class<R> serviceRole) {
if ( JdbcServices.class.equals( serviceRole ) ) {
// return a new, not fully initialized JdbcServicesImpl
return (R) new JdbcServicesImpl();
}
return super.getService( serviceRole );
}
public static CCTStandardServiceRegistryImpl create(
boolean autoCloseRegistry,
BootstrapServiceRegistry bootstrapServiceRegistry,
List<StandardServiceInitiator<?>> serviceInitiators,
List<ProvidedService<?>> providedServices,
Map<String,Object> configurationValues) {
CCTStandardServiceRegistryImpl instance = new CCTStandardServiceRegistryImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
instance.initialize();
instance.applyServiceRegistrations( serviceInitiators, providedServices );
return instance;
}
}
} }

View File

@ -85,8 +85,7 @@ public class HibernateQueryMetrics implements MeterBinder {
@Override @Override
public void bindTo(MeterRegistry meterRegistry) { public void bindTo(MeterRegistry meterRegistry) {
if ( sessionFactory instanceof SessionFactoryImplementor ) { if ( sessionFactory instanceof SessionFactoryImplementor ) {
EventListenerRegistry eventListenerRegistry = ( (SessionFactoryImplementor) sessionFactory ).getServiceRegistry() EventListenerRegistry eventListenerRegistry = ( (SessionFactoryImplementor) sessionFactory ).getEventEngine().getListenerRegistry();
.getService( EventListenerRegistry.class );
MetricsEventHandler metricsEventHandler = new MetricsEventHandler( meterRegistry ); MetricsEventHandler metricsEventHandler = new MetricsEventHandler( meterRegistry );
eventListenerRegistry.appendListeners( EventType.POST_LOAD, metricsEventHandler ); eventListenerRegistry.appendListeners( EventType.POST_LOAD, metricsEventHandler );
} }

View File

@ -33,8 +33,15 @@ public class ServiceRegistryTestingImpl
extends StandardServiceRegistryImpl extends StandardServiceRegistryImpl
implements ServiceRegistryImplementor { implements ServiceRegistryImplementor {
private ServiceRegistryTestingImpl(
boolean autoCloseRegistry,
BootstrapServiceRegistry bootstrapServiceRegistry,
Map<String, Object> configurationValues) {
super( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
}
public static ServiceRegistryTestingImpl forUnitTesting() { public static ServiceRegistryTestingImpl forUnitTesting() {
return new ServiceRegistryTestingImpl( return ServiceRegistryTestingImpl.create(
true, true,
new BootstrapServiceRegistryBuilder().build(), new BootstrapServiceRegistryBuilder().build(),
StandardServiceInitiators.LIST, StandardServiceInitiators.LIST,
@ -47,7 +54,7 @@ public class ServiceRegistryTestingImpl
} }
public static ServiceRegistryTestingImpl forUnitTesting(Map<String,Object> settings) { public static ServiceRegistryTestingImpl forUnitTesting(Map<String,Object> settings) {
return new ServiceRegistryTestingImpl( return ServiceRegistryTestingImpl.create(
true, true,
new BootstrapServiceRegistryBuilder().build(), new BootstrapServiceRegistryBuilder().build(),
StandardServiceInitiators.LIST, StandardServiceInitiators.LIST,
@ -70,12 +77,17 @@ public class ServiceRegistryTestingImpl
); );
} }
public ServiceRegistryTestingImpl( public static ServiceRegistryTestingImpl create(
boolean autoCloseRegistry, boolean autoCloseRegistry,
BootstrapServiceRegistry bootstrapServiceRegistry, BootstrapServiceRegistry bootstrapServiceRegistry,
List<StandardServiceInitiator<?>> serviceInitiators, List<StandardServiceInitiator<?>> serviceInitiators,
List<ProvidedService<?>> providedServices, List<ProvidedService<?>> providedServices,
Map<String,Object> configurationValues) { Map<String,Object> configurationValues) {
super( autoCloseRegistry, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
ServiceRegistryTestingImpl instance = new ServiceRegistryTestingImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
instance.initialize();
instance.applyServiceRegistrations( serviceInitiators, providedServices );
return instance;
} }
} }

View File

@ -150,7 +150,7 @@ public abstract class MockSessionFactory
public MockSessionFactory() { public MockSessionFactory() {
serviceRegistry = new StandardServiceRegistryImpl( serviceRegistry = StandardServiceRegistryImpl.create(
new BootstrapServiceRegistryBuilder().applyClassLoaderService(new ClassLoaderServiceImpl() { new BootstrapServiceRegistryBuilder().applyClassLoaderService(new ClassLoaderServiceImpl() {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")