Skip to content

Commit c5c3bb8

Browse files
committed
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 <[email protected]>
1 parent 781cdc8 commit c5c3bb8

File tree

44 files changed

+247
-147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+247
-147
lines changed

gradle/java-module.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ checkerFramework {
544544
extraJavacArgs = [
545545
'-AsuppressWarnings=initialization',
546546
// stubs is passed directly through options.compilerArgumentProviders
547-
'-AonlyDefs=^org\\.hibernate\\.(jpamodelgen|spi|pretty|stat|engine\\.(profile|transaction)|(action|context|bytecode)\\.spi)\\.'
547+
'-AonlyDefs=^org\\.hibernate\\.(exception|integrator|jpamodelgen|service|spi|pretty|stat|engine\\.(config|jndi|profile|transaction)|(action|context|bytecode)\\.spi)\\.'
548548
]
549549
}
550550

hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -659,10 +659,6 @@ public MetadataBuildingOptionsImpl(StandardServiceRegistry serviceRegistry) {
659659
this.sharedCacheMode = configService.getSetting(
660660
AvailableSettings.JAKARTA_SHARED_CACHE_MODE,
661661
value -> {
662-
if ( value == null ) {
663-
return null;
664-
}
665-
666662
if ( value instanceof SharedCacheMode ) {
667663
return (SharedCacheMode) value;
668664
}

hibernate-core/src/main/java/org/hibernate/boot/registry/BootstrapServiceRegistryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public BootstrapServiceRegistry build() {
187187
classLoaderService = providedClassLoaderService;
188188
}
189189

190-
final IntegratorServiceImpl integratorService = new IntegratorServiceImpl(
190+
final IntegratorServiceImpl integratorService = IntegratorServiceImpl.create(
191191
providedIntegrators,
192192
classLoaderService
193193
);

hibernate-core/src/main/java/org/hibernate/boot/registry/StandardServiceRegistryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ public StandardServiceRegistry build() {
365365
settingsCopy.put( LOADED_CONFIG_KEY, aggregatedCfgXml );
366366
ConfigurationHelper.resolvePlaceHolders( settingsCopy );
367367

368-
return new StandardServiceRegistryImpl(
368+
return StandardServiceRegistryImpl.create(
369369
autoCloseRegistry,
370370
bootstrapServiceRegistry,
371371
initiators,

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.hibernate.service.spi.ServiceRegistryImplementor;
3030
import org.hibernate.service.spi.Stoppable;
3131

32+
import org.checkerframework.checker.nullness.qual.Nullable;
33+
3234
/**
3335
* {@link ServiceRegistry} implementation containing specialized "bootstrap" services, specifically:<ul>
3436
* <li>{@link ClassLoaderService}</li>
@@ -117,7 +119,7 @@ public BootstrapServiceRegistryImpl(
117119
this.integratorServiceBinding = new ServiceBinding<>(
118120
this,
119121
IntegratorService.class,
120-
new IntegratorServiceImpl( providedIntegrators, classLoaderService )
122+
IntegratorServiceImpl.create( providedIntegrators, classLoaderService )
121123
);
122124
}
123125

@@ -185,7 +187,7 @@ public BootstrapServiceRegistryImpl(
185187

186188

187189
@Override
188-
public <R extends Service> R getService(Class<R> serviceRole) {
190+
public <R extends Service> @Nullable R getService(Class<R> serviceRole) {
189191
final ServiceBinding<R> binding = locateServiceBinding( serviceRole );
190192
return binding == null ? null : binding.getService();
191193
}
@@ -235,7 +237,7 @@ public boolean isActive() {
235237
}
236238

237239
@Override
238-
public ServiceRegistry getParentServiceRegistry() {
240+
public @Nullable ServiceRegistry getParentServiceRegistry() {
239241
return null;
240242
}
241243

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
3030
//Access to this field requires synchronization on -this-
3131
private Map<String,Object> configurationValues;
3232

33+
protected StandardServiceRegistryImpl(
34+
boolean autoCloseRegistry,
35+
BootstrapServiceRegistry bootstrapServiceRegistry,
36+
Map<String,Object> configurationValues) {
37+
super( bootstrapServiceRegistry, autoCloseRegistry );
38+
this.configurationValues = configurationValues;
39+
}
40+
3341
/**
3442
* Constructs a StandardServiceRegistryImpl. Should not be instantiated directly; use
3543
* {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder} instead
@@ -41,12 +49,13 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
4149
*
4250
* @see org.hibernate.boot.registry.StandardServiceRegistryBuilder
4351
*/
44-
public StandardServiceRegistryImpl(
52+
public static StandardServiceRegistryImpl create(
4553
BootstrapServiceRegistry bootstrapServiceRegistry,
4654
List<StandardServiceInitiator<?>> serviceInitiators,
4755
List<ProvidedService<?>> providedServices,
4856
Map<String,Object> configurationValues) {
49-
this( true, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
57+
58+
return create( true, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
5059
}
5160

5261
/**
@@ -62,20 +71,21 @@ public StandardServiceRegistryImpl(
6271
*
6372
* @see org.hibernate.boot.registry.StandardServiceRegistryBuilder
6473
*/
65-
public StandardServiceRegistryImpl(
74+
public static StandardServiceRegistryImpl create(
6675
boolean autoCloseRegistry,
6776
BootstrapServiceRegistry bootstrapServiceRegistry,
6877
List<StandardServiceInitiator<?>> serviceInitiators,
6978
List<ProvidedService<?>> providedServices,
7079
Map<String,Object> configurationValues) {
71-
super( bootstrapServiceRegistry, autoCloseRegistry );
7280

73-
this.configurationValues = configurationValues;
81+
StandardServiceRegistryImpl instance = new StandardServiceRegistryImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
82+
instance.initialize();
83+
instance.applyServiceRegistrations( serviceInitiators, providedServices );
7484

75-
applyServiceRegistrations( serviceInitiators, providedServices );
85+
return instance;
7686
}
7787

78-
private void applyServiceRegistrations(List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) {
88+
protected void applyServiceRegistrations(List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) {
7989
try {
8090
// process initiators
8191
for ( ServiceInitiator<?> initiator : serviceInitiators ) {

hibernate-core/src/main/java/org/hibernate/cache/spi/access/AccessType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import java.util.Locale;
1010

11+
import org.checkerframework.checker.nullness.qual.Nullable;
12+
1113
/**
1214
* Enumerates the policies for managing concurrent access to the shared
1315
* second-level cache.
@@ -70,7 +72,7 @@ public String toString() {
7072
*
7173
* @see #getExternalName()
7274
*/
73-
public static AccessType fromExternalName(String externalName) {
75+
public static AccessType fromExternalName(@Nullable String externalName) {
7476
if ( externalName == null ) {
7577
return null;
7678
}

hibernate-core/src/main/java/org/hibernate/engine/config/internal/ConfigurationServiceImpl.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
1414
import org.hibernate.engine.config.spi.ConfigurationService;
1515
import org.hibernate.internal.CoreMessageLogger;
16+
import org.hibernate.internal.util.NullnessUtil;
1617
import org.hibernate.service.spi.ServiceRegistryAwareService;
1718
import org.hibernate.service.spi.ServiceRegistryImplementor;
1819

1920
import org.jboss.logging.Logger;
2021

22+
import org.checkerframework.checker.nullness.qual.Nullable;
23+
import org.checkerframework.checker.nullness.qual.PolyNull;
24+
2125
/**
2226
* The standard {@link ConfigurationService} implementation.
2327
*
@@ -52,12 +56,12 @@ public void injectServices(ServiceRegistryImplementor serviceRegistry) {
5256
}
5357

5458
@Override
55-
public <T> T getSetting(String name, Converter<T> converter) {
59+
public <T> @Nullable T getSetting(String name, Converter<T> converter) {
5660
return getSetting( name, converter, null );
5761
}
5862

5963
@Override
60-
public <T> T getSetting(String name, Converter<T> converter, T defaultValue) {
64+
public <T> @PolyNull T getSetting(String name, Converter<T> converter, @PolyNull T defaultValue) {
6165
final Object value = settings.get( name );
6266
if ( value == null ) {
6367
return defaultValue;
@@ -67,14 +71,14 @@ public <T> T getSetting(String name, Converter<T> converter, T defaultValue) {
6771
}
6872

6973
@Override
70-
public <T> T getSetting(String name, Class<T> expected, T defaultValue) {
74+
public <T> @PolyNull T getSetting(String name, Class<T> expected, @PolyNull T defaultValue) {
7175
final Object value = settings.get( name );
7276
final T target = cast( expected, value );
7377
return target !=null ? target : defaultValue;
7478
}
7579

7680
@SuppressWarnings("unchecked")
77-
public <T> T cast(Class<T> expected, Object candidate){
81+
public <T> @Nullable T cast(Class<T> expected, @Nullable Object candidate){
7882
if (candidate == null) {
7983
return null;
8084
}
@@ -89,7 +93,7 @@ public <T> T cast(Class<T> expected, Object candidate){
8993
}
9094
else {
9195
try {
92-
target = serviceRegistry.getService( ClassLoaderService.class ).classForName( candidate.toString() );
96+
target = NullnessUtil.castNonNull( serviceRegistry.getService( ClassLoaderService.class ) ).classForName( candidate.toString() );
9397
}
9498
catch ( ClassLoadingException e ) {
9599
LOG.debugf( "Unable to locate %s implementation class %s", expected.getName(), candidate.toString() );

hibernate-core/src/main/java/org/hibernate/engine/config/spi/ConfigurationService.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
import org.hibernate.service.Service;
1212

13+
import org.checkerframework.checker.nullness.qual.NonNull;
14+
import org.checkerframework.checker.nullness.qual.Nullable;
15+
import org.checkerframework.checker.nullness.qual.PolyNull;
16+
1317
/**
1418
* Provides access to the initial user-provided configuration values. Generally speaking
1519
* these values come from:<ul>
@@ -38,7 +42,7 @@ public interface ConfigurationService extends Service {
3842
*
3943
* @return The converted (typed) setting. May return {@code null} (see {@link #getSetting(String, Class, Object)})
4044
*/
41-
<T> T getSetting(String name, Converter<T> converter);
45+
<T> @Nullable T getSetting(String name, Converter<T> converter);
4246

4347
/**
4448
* Get the named setting, using the specified converter and default value.
@@ -50,7 +54,7 @@ public interface ConfigurationService extends Service {
5054
*
5155
* @return The converted (typed) setting. Will be the defaultValue if no such setting was defined.
5256
*/
53-
<T> T getSetting(String name, Converter<T> converter, T defaultValue);
57+
<T> @PolyNull T getSetting(String name, Converter<T> converter, @PolyNull T defaultValue);
5458

5559
/**
5660
* 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 {
6367
*
6468
* @return The converted (typed) setting. Will be the defaultValue if no such setting was defined.
6569
*/
66-
<T> T getSetting(String name, Class<T> expected, T defaultValue);
70+
<T> @PolyNull T getSetting(String name, Class<T> expected, @PolyNull T defaultValue);
6771

6872
/**
6973
* Simple conversion contract for converting an untyped object to a specified type.
@@ -78,6 +82,6 @@ interface Converter<T> {
7882
*
7983
* @return The converted (typed) value.
8084
*/
81-
T convert(Object value);
85+
@NonNull T convert(Object value);
8286
}
8387
}

hibernate-core/src/main/java/org/hibernate/engine/config/spi/StandardConverters.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
package org.hibernate.engine.config.spi;
88

99

10+
import org.checkerframework.checker.nullness.qual.PolyNull;
11+
1012
import static org.hibernate.engine.config.spi.ConfigurationService.Converter;
1113

1214
/**
@@ -18,10 +20,6 @@ public class StandardConverters {
1820
public static final Converter<Boolean> BOOLEAN = StandardConverters::asBoolean;
1921

2022
public static Boolean asBoolean(Object value) {
21-
if ( value == null ) {
22-
throw new IllegalArgumentException( "Null value passed to convert" );
23-
}
24-
2523
return value instanceof Boolean
2624
? (Boolean) value
2725
: Boolean.parseBoolean( value.toString() );
@@ -30,20 +28,12 @@ public static Boolean asBoolean(Object value) {
3028
public static final Converter<String> STRING = StandardConverters::asString;
3129

3230
public static String asString(Object value) {
33-
if ( value == null ) {
34-
throw new IllegalArgumentException( "Null value passed to convert" );
35-
}
36-
3731
return value.toString();
3832
}
3933

4034
public static final Converter<Integer> INTEGER = StandardConverters::asInteger;
4135

4236
public static Integer asInteger(Object value) {
43-
if ( value == null ) {
44-
throw new IllegalArgumentException( "Null value passed to convert" );
45-
}
46-
4737
if ( value instanceof Number ) {
4838
return ( (Number) value ).intValue();
4939
}

0 commit comments

Comments
 (0)