HHH-16515 - Add o.h.property.access.spi to nullness checking

HHH-16515 - Add o.h.property.access.internal to nullness checking

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2023-07-05 18:48:15 +02:00 committed by Christian Beikov
parent 22091b2254
commit 58c10758e0
31 changed files with 163 additions and 111 deletions

View File

@ -5,5 +5,10 @@ package java.lang.reflect;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class Method extends Executable {
void invoke(@Nullable Object obj, Object @Nullable ... args);
void invoke(@Nullable Object obj, @Nullable Object @Nullable ... args);
}
public final
class Field extends AccessibleObject implements Member {
public void set(Object obj, @Nullable Object value);
}

View File

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

View File

@ -8,6 +8,8 @@ package org.hibernate;
import static org.hibernate.internal.util.StringHelper.qualify;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* A problem occurred accessing a property of an instance of a
* persistent class by reflection, or via enhanced entities.
@ -38,7 +40,7 @@ public class PropertyAccessException extends HibernateException {
* @param propertyName The name of the property.
*/
public PropertyAccessException(
Throwable cause,
@Nullable Throwable cause,
String message,
boolean wasSetter,
Class<?> persistentClass,

View File

@ -8,6 +8,8 @@ package org.hibernate;
import java.util.Collection;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* @author Steve Ebersole
*/
@ -28,7 +30,7 @@ public class PropertySetterAccessException extends PropertyAccessException {
String propertyName,
Class<?> expectedType,
Object target,
Object value) {
@Nullable Object value) {
super(
cause,
String.format(

View File

@ -19,6 +19,8 @@ import org.hibernate.proxy.HibernateProxy;
import java.util.Objects;
import java.util.function.BiConsumer;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* This is a helper to encapsulate an optimal strategy to execute type checks
* for interfaces which attempts to avoid the performance issues tracked
@ -158,7 +160,7 @@ public final class ManagedTypeHelper {
* @param entity
* @return true if and only if the entity implements {@see CompositeTracker}
*/
public static boolean isCompositeTracker(final Object entity) {
public static boolean isCompositeTracker(final @Nullable Object entity) {
if ( entity instanceof PrimeAmongSecondarySupertypes ) {
PrimeAmongSecondarySupertypes t = (PrimeAmongSecondarySupertypes) entity;
return t.asCompositeTracker() != null;

View File

@ -44,6 +44,7 @@ import org.jboss.logging.annotations.ValidIdRange;
import jakarta.transaction.Synchronization;
import jakarta.transaction.SystemException;
import org.checkerframework.checker.nullness.qual.Nullable;
import static org.jboss.logging.Logger.Level.DEBUG;
import static org.jboss.logging.Logger.Level.ERROR;
@ -278,7 +279,7 @@ public interface CoreMessageLogger extends BasicLogger {
@LogMessage(level = ERROR)
@Message(value = "Expected type: %s, actual value: %s", id = 91)
void expectedType(String name,
String string);
@Nullable String string);
@LogMessage(level = WARN)
@Message(value = "An item was expired by the cache while it was locked (increase your cache timeout): %s", id = 92)

View File

@ -19,10 +19,13 @@ import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInter
import org.hibernate.engine.spi.CompositeOwner;
import org.hibernate.engine.spi.CompositeTracker;
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
import org.hibernate.internal.util.NullnessHelper;
import org.hibernate.internal.util.NullnessUtil;
import jakarta.persistence.Access;
import jakarta.persistence.AccessType;
import jakarta.persistence.Transient;
import org.checkerframework.checker.nullness.qual.Nullable;
import static org.hibernate.engine.internal.ManagedTypeHelper.asCompositeOwner;
import static org.hibernate.engine.internal.ManagedTypeHelper.asCompositeTracker;
@ -41,7 +44,7 @@ public class AccessStrategyHelper {
public static final int COMPOSITE_OWNER = 2;
public static final int PERSISTENT_ATTRIBUTE_INTERCEPTABLE_MASK = 4;
public static Field fieldOrNull(Class<?> containerJavaType, String propertyName) {
public static @Nullable Field fieldOrNull(Class<?> containerJavaType, String propertyName) {
try {
return findField( containerJavaType, propertyName );
}
@ -67,7 +70,7 @@ public class AccessStrategyHelper {
return field != null ? AccessType.FIELD : AccessType.PROPERTY;
}
public static AccessType getExplicitAccessType(Class<?> containerClass, String propertyName, Field field) {
public static @Nullable AccessType getExplicitAccessType(Class<?> containerClass, String propertyName, @Nullable Field field) {
if ( isRecord( containerClass ) ) {
try {
containerClass.getMethod( propertyName, NO_PARAM_SIGNATURE );
@ -160,7 +163,7 @@ public class AccessStrategyHelper {
}
}
public static Method findIsMethodVariant(Class<?> containerClass, String stemName) {
public static @Nullable Method findIsMethodVariant(Class<?> containerClass, String stemName) {
// verify that the Class does not also define a method with the same stem name with 'is'
try {
final Method isMethod = containerClass.getDeclaredMethod( "is" + stemName );
@ -174,7 +177,7 @@ public class AccessStrategyHelper {
return null;
}
protected static AccessType getAccessTypeOrNull(AnnotatedElement element) {
protected static @Nullable AccessType getAccessTypeOrNull(@Nullable AnnotatedElement element) {
if ( element == null ) {
return null;
}
@ -188,13 +191,13 @@ public class AccessStrategyHelper {
| ( isPersistentAttributeInterceptableType( containerClass ) ? AccessStrategyHelper.PERSISTENT_ATTRIBUTE_INTERCEPTABLE_MASK : 0 );
}
public static void handleEnhancedInjection(Object target, Object value, int enhancementState, String propertyName) {
public static void handleEnhancedInjection(Object target, @Nullable Object value, int enhancementState, String propertyName) {
// This sets the component relation for dirty tracking purposes
if ( ( enhancementState & COMPOSITE_OWNER ) != 0
&& ( ( enhancementState & COMPOSITE_TRACKER_MASK ) != 0
&& value != null
|| isCompositeTracker( value ) ) ) {
asCompositeTracker( value ).$$_hibernate_setOwner( propertyName, asCompositeOwner( target ) );
asCompositeTracker( NullnessUtil.castNonNull(value) ).$$_hibernate_setOwner( propertyName, asCompositeOwner( target ) );
}
// This marks the attribute as initialized, so it doesn't get lazily loaded afterward

View File

@ -12,11 +12,14 @@ import java.lang.reflect.Type;
import java.util.Map;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.property.access.spi.Getter;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.PropertyAccessStrategy;
import org.hibernate.property.access.spi.Setter;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* @author Christian Beikov
*/
@ -44,24 +47,26 @@ public class ChainedPropertyAccessImpl implements PropertyAccess, Getter, Setter
}
@Override
public Object get(Object owner) {
public @Nullable Object get(Object owner) {
@Nullable Object result = owner;
for ( int i = 0; i < propertyAccesses.length; i++ ) {
owner = propertyAccesses[i].getGetter().get( owner );
result = propertyAccesses[i].getGetter().get( NullnessUtil.castNonNull( result ) );
}
return owner;
return result;
}
@SuppressWarnings("rawtypes")
@Override
public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
@Nullable Object result = owner;
for ( int i = 0; i < propertyAccesses.length; i++ ) {
owner = propertyAccesses[i].getGetter().getForInsert( owner, mergeMap, session );
result = propertyAccesses[i].getGetter().getForInsert( NullnessUtil.castNonNull( result ), mergeMap, session );
}
return owner;
return result;
}
@Override
public void set(Object target, Object value) {
public void set(Object target, @Nullable Object value) {
throw new UnsupportedOperationException();
}
@ -76,17 +81,17 @@ public class ChainedPropertyAccessImpl implements PropertyAccess, Getter, Setter
}
@Override
public Member getMember() {
public @Nullable Member getMember() {
return null;
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return null;
}
}

View File

@ -18,6 +18,8 @@ import org.hibernate.property.access.spi.SetterMethodImpl;
import org.jboss.logging.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* {@link PropertyAccess} for accessing the wrapped property via get/set pair, which may be nonpublic.
*
@ -30,7 +32,7 @@ public class PropertyAccessBasicImpl implements PropertyAccess {
private final PropertyAccessStrategyBasicImpl strategy;
private final GetterMethodImpl getter;
private final SetterMethodImpl setter;
private final @Nullable SetterMethodImpl setter;
public PropertyAccessBasicImpl(
PropertyAccessStrategyBasicImpl strategy,
@ -65,7 +67,7 @@ public class PropertyAccessBasicImpl implements PropertyAccess {
}
@Override
public Setter getSetter() {
public @Nullable Setter getSetter() {
return setter;
}
}

View File

@ -18,6 +18,8 @@ import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.PropertyAccessStrategy;
import org.hibernate.property.access.spi.Setter;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* {@link PropertyAccess} for accessing the wrapped property via get/set pair, which may be nonpublic.
*
@ -46,18 +48,18 @@ public class PropertyAccessCompositeUserTypeImpl implements PropertyAccess, Gett
}
@Override
public Setter getSetter() {
public @Nullable Setter getSetter() {
return null;
}
@Override
public Object get(Object owner) {
public @Nullable Object get(Object owner) {
return strategy.compositeUserType.getPropertyValue( owner, propertyIndex );
}
@SuppressWarnings("rawtypes")
@Override
public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
return get( owner );
}
@ -72,17 +74,17 @@ public class PropertyAccessCompositeUserTypeImpl implements PropertyAccess, Gett
}
@Override
public Member getMember() {
public @Nullable Member getMember() {
return null;
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return null;
}
}

View File

@ -17,6 +17,8 @@ import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.PropertyAccessStrategy;
import org.hibernate.property.access.spi.Setter;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* {@link PropertyAccess} for handling non-aggregated composites.
*
@ -84,17 +86,17 @@ public class PropertyAccessEmbeddedImpl implements PropertyAccess {
}
@Override
public Member getMember() {
public @Nullable Member getMember() {
return null;
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return null;
}
}
@ -106,17 +108,17 @@ public class PropertyAccessEmbeddedImpl implements PropertyAccess {
public static final SetterImpl INSTANCE = new SetterImpl();
@Override
public void set(Object target, Object value) {
public void set(Object target, @Nullable Object value) {
// nothing to do
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return null;
}
}

View File

@ -20,6 +20,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.Method;
import jakarta.persistence.AccessType;
import org.checkerframework.checker.nullness.qual.Nullable;
import static org.hibernate.internal.util.ReflectHelper.findSetterMethod;
import static org.hibernate.internal.util.ReflectHelper.getterMethodOrNull;
@ -42,7 +43,7 @@ public class PropertyAccessEnhancedImpl implements PropertyAccess {
PropertyAccessStrategy strategy,
Class<?> containerJavaType,
String propertyName,
AccessType getterAccessType) {
@Nullable AccessType getterAccessType) {
this.strategy = strategy;
final AccessType propertyAccessType = resolveAccessType( getterAccessType, containerJavaType, propertyName );
@ -80,7 +81,7 @@ public class PropertyAccessEnhancedImpl implements PropertyAccess {
}
}
private AccessType resolveAccessType(AccessType getterAccessType, Class<?> containerJavaType, String propertyName) {
private static AccessType resolveAccessType(@Nullable AccessType getterAccessType, Class<?> containerJavaType, String propertyName) {
if ( getterAccessType != null ) {
// this should indicate FIELD access
return getterAccessType;

View File

@ -17,6 +17,8 @@ import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.PropertyAccessStrategy;
import org.hibernate.property.access.spi.Setter;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* {@link PropertyAccess} implementation that deals with an underlying {@code Map}
* as the container, using {@link Map#get} and {@link Map#put}.
@ -59,12 +61,12 @@ public class PropertyAccessMapImpl implements PropertyAccess {
@Override
@SuppressWarnings("rawtypes")
public Object get(Object owner) {
public @Nullable Object get(Object owner) {
return ( (Map) owner ).get( propertyName );
}
@Override
public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
return get( owner );
}
@ -80,17 +82,17 @@ public class PropertyAccessMapImpl implements PropertyAccess {
}
@Override
public Member getMember() {
public @Nullable Member getMember() {
return null;
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return null;
}
}
@ -104,17 +106,17 @@ public class PropertyAccessMapImpl implements PropertyAccess {
@Override
@SuppressWarnings("unchecked")
public void set(Object target, Object value) {
public void set(Object target, @Nullable Object value) {
( (Map) target ).put( propertyName, value );
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return null;
}
}

View File

@ -20,6 +20,7 @@ import org.hibernate.property.access.spi.SetterFieldImpl;
import org.hibernate.property.access.spi.SetterMethodImpl;
import jakarta.persistence.AccessType;
import org.checkerframework.checker.nullness.qual.PolyNull;
import static org.hibernate.internal.util.ReflectHelper.findSetterMethod;
import static org.hibernate.internal.util.ReflectHelper.getterMethodOrNull;
@ -74,19 +75,19 @@ public class PropertyAccessMixedImpl implements PropertyAccess {
// --- //
protected Getter fieldGetter(Class<?> containerJavaType, String propertyName, Field field) {
private static Getter fieldGetter(Class<?> containerJavaType, String propertyName, Field field) {
return new GetterFieldImpl( containerJavaType, propertyName, field );
}
protected Setter fieldSetter(Class<?> containerJavaType, String propertyName, Field field) {
private static Setter fieldSetter(Class<?> containerJavaType, String propertyName, Field field) {
return new SetterFieldImpl( containerJavaType, propertyName, field );
}
protected Getter propertyGetter(Class<?> containerJavaType, String propertyName, Method method) {
private static Getter propertyGetter(Class<?> containerJavaType, String propertyName, Method method) {
return new GetterMethodImpl( containerJavaType, propertyName, method );
}
protected Setter propertySetter(Class<?> containerJavaType, String propertyName, Method method) {
private static @PolyNull Setter propertySetter(Class<?> containerJavaType, String propertyName, @PolyNull Method method) {
return method == null ? null : new SetterMethodImpl( containerJavaType, propertyName, method );
}

View File

@ -18,6 +18,8 @@ import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.PropertyAccessStrategy;
import org.hibernate.property.access.spi.Setter;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* @author Gavin King
* @author Steve Ebersole
@ -94,12 +96,7 @@ public class PropertyAccessStrategyBackRefImpl implements PropertyAccessStrategy
@Override
@SuppressWarnings("rawtypes")
public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
if ( session == null ) {
return UNKNOWN;
}
else {
return session.getPersistenceContextInternal().getOwnerId( entityName, propertyName, owner, mergeMap );
}
return session.getPersistenceContextInternal().getOwnerId( entityName, propertyName, owner, mergeMap );
}
@Override
@ -113,17 +110,17 @@ public class PropertyAccessStrategyBackRefImpl implements PropertyAccessStrategy
}
@Override
public Member getMember() {
public @Nullable Member getMember() {
return null;
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return null;
}
}
@ -135,17 +132,17 @@ public class PropertyAccessStrategyBackRefImpl implements PropertyAccessStrategy
public static final SetterImpl INSTANCE = new SetterImpl();
@Override
public void set(Object target, Object value) {
public void set(Object target, @Nullable Object value) {
// this page intentionally left blank :)
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return null;
}
}

View File

@ -10,6 +10,7 @@ import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.PropertyAccessStrategy;
import jakarta.persistence.AccessType;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Defines a strategy for accessing property values via a get/set pair, which may be nonpublic. This
@ -26,12 +27,12 @@ public class PropertyAccessStrategyEnhancedImpl implements PropertyAccessStrateg
return STANDARD;
}
private final AccessType getterAccessType;
private final @Nullable AccessType getterAccessType;
public static PropertyAccessStrategyEnhancedImpl STANDARD = new PropertyAccessStrategyEnhancedImpl( null );
public static PropertyAccessStrategyEnhancedImpl FIELD = new PropertyAccessStrategyEnhancedImpl( AccessType.FIELD );
public PropertyAccessStrategyEnhancedImpl(AccessType getterAccessType) {
public PropertyAccessStrategyEnhancedImpl(@Nullable AccessType getterAccessType) {
this.getterAccessType = getterAccessType;
}

View File

@ -17,6 +17,8 @@ import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.PropertyAccessStrategy;
import org.hibernate.property.access.spi.Setter;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* @author Gavin King
* @author Steve Ebersole
@ -77,12 +79,7 @@ public class PropertyAccessStrategyIndexBackRefImpl implements PropertyAccessStr
@SuppressWarnings("rawtypes")
@Override
public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
if ( session == null ) {
return PropertyAccessStrategyBackRefImpl.UNKNOWN;
}
else {
return session.getPersistenceContextInternal().getIndexInOwner( entityName, propertyName, owner, mergeMap );
}
return session.getPersistenceContextInternal().getIndexInOwner( entityName, propertyName, owner, mergeMap );
}
@Override
@ -96,17 +93,17 @@ public class PropertyAccessStrategyIndexBackRefImpl implements PropertyAccessStr
}
@Override
public Member getMember() {
public @Nullable Member getMember() {
return null;
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return null;
}
}
@ -118,17 +115,17 @@ public class PropertyAccessStrategyIndexBackRefImpl implements PropertyAccessStr
public static final SetterImpl INSTANCE = new SetterImpl();
@Override
public void set(Object target, Object value) {
public void set(Object target, @Nullable Object value) {
// this page intentionally left blank :)
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return null;
}
}

View File

@ -11,6 +11,8 @@ import java.util.Map;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.PropertyAccessStrategy;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* @author Steve Ebersole
* @author Gavin King
@ -22,7 +24,7 @@ public class PropertyAccessStrategyMapImpl implements PropertyAccessStrategy {
public static final PropertyAccessStrategyMapImpl INSTANCE = new PropertyAccessStrategyMapImpl();
@Override
public PropertyAccess buildPropertyAccess(Class<?> containerJavaType, String propertyName, boolean setterRequired) {
public PropertyAccess buildPropertyAccess(@Nullable Class<?> containerJavaType, String propertyName, boolean setterRequired) {
// Sometimes containerJavaType is null, but if it isn't, make sure it's a Map.
if (containerJavaType != null && !Map.class.isAssignableFrom( containerJavaType)) {

View File

@ -17,6 +17,8 @@ import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.property.access.spi.PropertyAccessStrategy;
import org.hibernate.property.access.spi.Setter;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* @author Michael Bartmann
* @author Gavin King
@ -62,13 +64,13 @@ public class PropertyAccessStrategyNoopImpl implements PropertyAccessStrategy {
public static final GetterImpl INSTANCE = new GetterImpl();
@Override
public Object get(Object owner) {
public @Nullable Object get(Object owner) {
return null;
}
@Override
@SuppressWarnings("rawtypes")
public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
return null;
}
@ -83,17 +85,17 @@ public class PropertyAccessStrategyNoopImpl implements PropertyAccessStrategy {
}
@Override
public Member getMember() {
public @Nullable Member getMember() {
return null;
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return null;
}
}
@ -105,16 +107,16 @@ public class PropertyAccessStrategyNoopImpl implements PropertyAccessStrategy {
public static final SetterImpl INSTANCE = new SetterImpl();
@Override
public void set(Object target, Object value) {
public void set(Object target, @Nullable Object value) {
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return null;
}
}

View File

@ -8,6 +8,7 @@ package org.hibernate.property.access.internal;
import org.hibernate.HibernateException;
import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.RepresentationMode;
import org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies;
@ -79,7 +80,7 @@ public class PropertyAccessStrategyResolverStandardImpl implements PropertyAcces
if ( serviceRegistry == null ) {
throw new HibernateException( "ServiceRegistry not yet injected; PropertyAccessStrategyResolver not ready for use." );
}
strategySelectorService = serviceRegistry.getService( StrategySelector.class );
strategySelectorService = NullnessUtil.castNonNull( serviceRegistry.getService( StrategySelector.class ) );
}
return strategySelectorService;
}

View File

@ -13,6 +13,8 @@ import org.hibernate.property.access.internal.PropertyAccessStrategyMapImpl;
import org.hibernate.property.access.internal.PropertyAccessStrategyMixedImpl;
import org.hibernate.property.access.internal.PropertyAccessStrategyNoopImpl;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Describes the built-in externally-nameable {@link PropertyAccessStrategy} implementations.
*
@ -42,7 +44,7 @@ public enum BuiltInPropertyAccessStrategies {
return strategy;
}
public static BuiltInPropertyAccessStrategies interpret(String name) {
public static @Nullable BuiltInPropertyAccessStrategies interpret(String name) {
for ( BuiltInPropertyAccessStrategies strategy : values() ) {
if ( strategy.externalName.equals( name ) ) {
return strategy;

View File

@ -13,6 +13,8 @@ import org.hibernate.Internal;
import org.hibernate.property.access.internal.AbstractFieldSerialForm;
import org.hibernate.property.access.internal.AccessStrategyHelper;
import org.checkerframework.checker.nullness.qual.Nullable;
import static org.hibernate.property.access.internal.AccessStrategyHelper.determineEnhancementState;
/**
@ -36,7 +38,7 @@ public class EnhancedSetterImpl extends SetterFieldImpl {
}
@Override
public void set(Object target, Object value) {
public void set(Object target, @Nullable Object value) {
super.set( target, value );
AccessStrategyHelper.handleEnhancedInjection( target, value, enhancementState, propertyName );
}

View File

@ -13,6 +13,8 @@ import org.hibernate.Internal;
import org.hibernate.property.access.internal.AbstractSetterMethodSerialForm;
import org.hibernate.property.access.internal.AccessStrategyHelper;
import org.checkerframework.checker.nullness.qual.Nullable;
import static org.hibernate.property.access.internal.AccessStrategyHelper.determineEnhancementState;
/**
@ -35,7 +37,7 @@ public class EnhancedSetterMethodImpl extends SetterMethodImpl {
}
@Override
public void set(Object target, Object value) {
public void set(Object target, @Nullable Object value) {
super.set( target, value );
AccessStrategyHelper.handleEnhancedInjection( target, value, enhancementState, propertyName );

View File

@ -14,6 +14,8 @@ import java.util.Map;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* The contract for getting the value of a persistent attribute from its container/owner.
*
@ -28,7 +30,7 @@ public interface Getter extends Serializable {
*
* @return The extracted value.
*/
Object get(Object owner);
@Nullable Object get(Object owner);
/**
* Get the property value from the given owner instance.
@ -39,7 +41,7 @@ public interface Getter extends Serializable {
*
* @return The extracted value.
*/
Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session);
@Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session);
/**
* Retrieve the declared Java type class
@ -63,7 +65,7 @@ public interface Getter extends Serializable {
*
* @return The mapped member, or {@code null}.
*/
Member getMember();
@Nullable Member getMember();
/**
* Retrieve the getter-method name.
@ -72,7 +74,7 @@ public interface Getter extends Serializable {
*
* @return The name of the getter method, or {@code null}.
*/
String getMethodName();
@Nullable String getMethodName();
/**
* Retrieve the getter-method.
@ -81,5 +83,5 @@ public interface Getter extends Serializable {
*
* @return The getter method, or {@code null}.
*/
Method getMethod();
@Nullable Method getMethod();
}

View File

@ -20,6 +20,8 @@ import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.property.access.internal.AbstractFieldSerialForm;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Field-based implementation of Getter
*
@ -30,7 +32,7 @@ public class GetterFieldImpl implements Getter {
private final Class<?> containerClass;
private final String propertyName;
private final Field field;
private final Method getterMethod;
private final @Nullable Method getterMethod;
public GetterFieldImpl(Class<?> containerClass, String propertyName, Field field) {
this.containerClass = containerClass;
@ -41,7 +43,7 @@ public class GetterFieldImpl implements Getter {
}
@Override
public Object get(Object owner) {
public @Nullable Object get(Object owner) {
try {
return field.get( owner );
}
@ -62,7 +64,7 @@ public class GetterFieldImpl implements Getter {
@SuppressWarnings("rawtypes")
@Override
public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
return get( owner );
}
@ -82,12 +84,12 @@ public class GetterFieldImpl implements Getter {
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return getterMethod != null ? getterMethod.getName() : null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return getterMethod;
}

View File

@ -21,6 +21,8 @@ import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.checkerframework.checker.nullness.qual.Nullable;
import static org.hibernate.internal.CoreLogging.messageLogger;
/**
@ -41,7 +43,7 @@ public class GetterMethodImpl implements Getter {
}
@Override
public Object get(Object owner) {
public @Nullable Object get(Object owner) {
try {
return getterMethod.invoke( owner, ArrayHelper.EMPTY_OBJECT_ARRAY );
}
@ -83,7 +85,7 @@ public class GetterMethodImpl implements Getter {
@SuppressWarnings("rawtypes")
@Override
public Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
public @Nullable Object getForInsert(Object owner, Map mergeMap, SharedSessionContractImplementor session) {
return get( owner );
}

View File

@ -8,6 +8,8 @@ package org.hibernate.property.access.spi;
import org.hibernate.metamodel.spi.ManagedTypeRepresentationStrategy;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Defines how a given persistent attribute is accessed by exposing
* a {@link Getter} and a {@link Setter} for the attribute.
@ -39,5 +41,5 @@ public interface PropertyAccess {
*
* @return The property setter
*/
Setter getSetter();
@Nullable Setter getSetter();
}

View File

@ -9,6 +9,8 @@ package org.hibernate.property.access.spi;
import java.io.Serializable;
import java.lang.reflect.Method;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* The contract for setting the value of a persistent attribute on its container/owner.
*
@ -17,15 +19,15 @@ import java.lang.reflect.Method;
*/
public interface Setter extends Serializable {
void set(Object target, Object value);
void set(Object target, @Nullable Object value);
/**
* Optional operation (may return {@code null})
*/
String getMethodName();
@Nullable String getMethodName();
/**
* Optional operation (may return {@code null})
*/
Method getMethod();
@Nullable Method getMethod();
}

View File

@ -18,6 +18,8 @@ import org.hibernate.property.access.internal.AbstractFieldSerialForm;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Field-based implementation of Setter
*
@ -28,7 +30,7 @@ public class SetterFieldImpl implements Setter {
private final Class<?> containerClass;
private final String propertyName;
private final Field field;
private final Method setterMethod;
private final @Nullable Method setterMethod;
public SetterFieldImpl(Class<?> containerClass, String propertyName, Field field) {
this.containerClass = containerClass;
@ -50,7 +52,7 @@ public class SetterFieldImpl implements Setter {
}
@Override
public void set(Object target, Object value) {
public void set(Object target, @Nullable Object value) {
try {
field.set( target, value );
}
@ -97,12 +99,12 @@ public class SetterFieldImpl implements Setter {
}
@Override
public String getMethodName() {
public @Nullable String getMethodName() {
return setterMethod != null ? setterMethod.getName() : null;
}
@Override
public Method getMethod() {
public @Nullable Method getMethod() {
return setterMethod;
}

View File

@ -16,6 +16,8 @@ import org.hibernate.PropertySetterAccessException;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.property.access.internal.AbstractSetterMethodSerialForm;
import org.checkerframework.checker.nullness.qual.Nullable;
import static org.hibernate.internal.CoreLogging.messageLogger;
/**
@ -40,7 +42,7 @@ public class SetterMethodImpl implements Setter {
}
@Override
public void set(Object target, Object value) {
public void set(Object target, @Nullable Object value) {
try {
setterMethod.invoke( target, value );
}

View File

@ -10,6 +10,8 @@ import java.io.Serializable;
import org.hibernate.Internal;
import org.hibernate.engine.spi.PrimeAmongSecondarySupertypes;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Interface implemented directly by entity proxies, exposing
* access to the associated {@link LazyInitializer}.
@ -27,7 +29,7 @@ public interface HibernateProxy extends Serializable, PrimeAmongSecondarySuperty
* @return the associated {@link LazyInitializer} if the given
* object is a proxy, or {@code null} otherwise.
*/
static LazyInitializer extractLazyInitializer(final Object object) {
static @Nullable LazyInitializer extractLazyInitializer(final @Nullable Object object) {
if ( object instanceof PrimeAmongSecondarySupertypes ) {
PrimeAmongSecondarySupertypes t = (PrimeAmongSecondarySupertypes) object;
final HibernateProxy hibernateProxy = t.asHibernateProxy();