diff --git a/checkerstubs/java.lang.astub b/checkerstubs/java.lang.astub index 54608ed501..f6a2418284 100644 --- a/checkerstubs/java.lang.astub +++ b/checkerstubs/java.lang.astub @@ -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); } diff --git a/gradle/java-module.gradle b/gradle/java-module.gradle index 8f31a2f2d2..181570e173 100644 --- a/gradle/java-module.gradle +++ b/gradle/java-module.gradle @@ -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)\\.' ] } diff --git a/hibernate-core/src/main/java/org/hibernate/PropertyAccessException.java b/hibernate-core/src/main/java/org/hibernate/PropertyAccessException.java index 82237d3e3c..4ba1afbf21 100644 --- a/hibernate-core/src/main/java/org/hibernate/PropertyAccessException.java +++ b/hibernate-core/src/main/java/org/hibernate/PropertyAccessException.java @@ -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, diff --git a/hibernate-core/src/main/java/org/hibernate/PropertySetterAccessException.java b/hibernate-core/src/main/java/org/hibernate/PropertySetterAccessException.java index 0f0783b2ac..a41c748beb 100644 --- a/hibernate-core/src/main/java/org/hibernate/PropertySetterAccessException.java +++ b/hibernate-core/src/main/java/org/hibernate/PropertySetterAccessException.java @@ -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( diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java index f64dd222a8..774c181660 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/ManagedTypeHelper.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index 9b8ffa0166..4fd931de52 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -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) diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/AccessStrategyHelper.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/AccessStrategyHelper.java index d337e25f77..db40f8e480 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/AccessStrategyHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/AccessStrategyHelper.java @@ -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 diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/ChainedPropertyAccessImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/ChainedPropertyAccessImpl.java index 33f92abddd..de76aca1ce 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/ChainedPropertyAccessImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/ChainedPropertyAccessImpl.java @@ -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; } } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessBasicImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessBasicImpl.java index 13ba975b78..7ff64fde3b 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessBasicImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessBasicImpl.java @@ -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; } } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessCompositeUserTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessCompositeUserTypeImpl.java index 78a4096d2e..aaf35ee5e4 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessCompositeUserTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessCompositeUserTypeImpl.java @@ -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; } } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEmbeddedImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEmbeddedImpl.java index 4c9b3cff34..a9f67dc4a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEmbeddedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEmbeddedImpl.java @@ -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; } } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEnhancedImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEnhancedImpl.java index 735d161d8e..3a6e3e51b4 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEnhancedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessEnhancedImpl.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMapImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMapImpl.java index 433fde5dd0..f2542eccf0 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMapImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMapImpl.java @@ -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; } } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMixedImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMixedImpl.java index b274e6641d..f1b26ce04c 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMixedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessMixedImpl.java @@ -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 ); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java index 904da3c3ad..58fbe780b2 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyBackRefImpl.java @@ -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; } } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyEnhancedImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyEnhancedImpl.java index f8c14f1515..33c5181552 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyEnhancedImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyEnhancedImpl.java @@ -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; } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java index 8112f6d57f..0c7f068107 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyIndexBackRefImpl.java @@ -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; } } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyMapImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyMapImpl.java index c1de791525..10f3b5083d 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyMapImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyMapImpl.java @@ -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)) { diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyNoopImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyNoopImpl.java index 8328565b99..a8133a7920 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyNoopImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyNoopImpl.java @@ -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; } } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyResolverStandardImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyResolverStandardImpl.java index 12bad9f270..7cc466a74b 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyResolverStandardImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyResolverStandardImpl.java @@ -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; } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/BuiltInPropertyAccessStrategies.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/BuiltInPropertyAccessStrategies.java index 168053e496..660bb4bb97 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/BuiltInPropertyAccessStrategies.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/BuiltInPropertyAccessStrategies.java @@ -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; diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterImpl.java index 1585159a48..8557334baf 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterImpl.java @@ -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 ); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterMethodImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterMethodImpl.java index 1a8513224d..4adc182eeb 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterMethodImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/EnhancedSetterMethodImpl.java @@ -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 ); diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/Getter.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/Getter.java index eb246f6382..e281365b6c 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/Getter.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/Getter.java @@ -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(); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterFieldImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterFieldImpl.java index 9b53f6a415..74647c5071 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterFieldImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterFieldImpl.java @@ -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; } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterMethodImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterMethodImpl.java index 6f1a948d11..ed63b969b8 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterMethodImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/GetterMethodImpl.java @@ -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 ); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/PropertyAccess.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/PropertyAccess.java index 207ca033c9..0b982e022f 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/PropertyAccess.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/PropertyAccess.java @@ -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(); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/Setter.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/Setter.java index f2d27e607c..119d6475d6 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/Setter.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/Setter.java @@ -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(); } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterFieldImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterFieldImpl.java index 8bffda51be..c4a8d49da4 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterFieldImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterFieldImpl.java @@ -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; } diff --git a/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterMethodImpl.java b/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterMethodImpl.java index ebbb9533dd..b9985f3ad5 100644 --- a/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterMethodImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/property/access/spi/SetterMethodImpl.java @@ -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 ); } diff --git a/hibernate-core/src/main/java/org/hibernate/proxy/HibernateProxy.java b/hibernate-core/src/main/java/org/hibernate/proxy/HibernateProxy.java index cb442104ed..0abb5e927d 100644 --- a/hibernate-core/src/main/java/org/hibernate/proxy/HibernateProxy.java +++ b/hibernate-core/src/main/java/org/hibernate/proxy/HibernateProxy.java @@ -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();