diff --git a/gradle/java-module.gradle b/gradle/java-module.gradle index 3c0852ed70..859e96e9f2 100644 --- a/gradle/java-module.gradle +++ b/gradle/java-module.gradle @@ -524,7 +524,7 @@ checkerFramework { extraJavacArgs = [ '-AsuppressWarnings=initialization', "-Astubs=${project.rootDir}/checkerstubs", - '-AonlyDefs=^org\\.hibernate\\.(jpamodelgen|spi|pretty)\\.' + '-AonlyDefs=^org\\.hibernate\\.(jpamodelgen|spi|pretty|(action|context|bytecode)\\.spi)\\.' ] } diff --git a/hibernate-core/src/main/java/org/hibernate/action/spi/Executable.java b/hibernate-core/src/main/java/org/hibernate/action/spi/Executable.java index 5795ad9045..52ec4b40ca 100644 --- a/hibernate-core/src/main/java/org/hibernate/action/spi/Executable.java +++ b/hibernate-core/src/main/java/org/hibernate/action/spi/Executable.java @@ -11,6 +11,8 @@ import java.io.Serializable; import org.hibernate.HibernateException; import org.hibernate.event.spi.EventSource; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * An operation which may be scheduled for later execution. Usually, the * operation is a database insert/update/delete, together with required @@ -47,7 +49,7 @@ public interface Executable { * @return The after-transaction-completion process, or null if we have no * after-transaction-completion process */ - AfterTransactionCompletionProcess getAfterTransactionCompletionProcess(); + @Nullable AfterTransactionCompletionProcess getAfterTransactionCompletionProcess(); /** * Get the before-transaction-completion process, if any, for this action. @@ -55,7 +57,7 @@ public interface Executable { * @return The before-transaction-completion process, or null if we have no * before-transaction-completion process */ - BeforeTransactionCompletionProcess getBeforeTransactionCompletionProcess(); + @Nullable BeforeTransactionCompletionProcess getBeforeTransactionCompletionProcess(); /** * Reconnect to session after deserialization diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/BytecodeEnhancementMetadataNonPojoImpl.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/BytecodeEnhancementMetadataNonPojoImpl.java index 4abf302fb3..172e02e56e 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/BytecodeEnhancementMetadataNonPojoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/BytecodeEnhancementMetadataNonPojoImpl.java @@ -16,6 +16,8 @@ import org.hibernate.engine.spi.PersistentAttributeInterceptable; import org.hibernate.engine.spi.PersistentAttributeInterceptor; import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * BytecodeEnhancementMetadata implementation for non-POJO models, mainly * {@link org.hibernate.metamodel.RepresentationMode#MAP} @@ -78,12 +80,12 @@ public class BytecodeEnhancementMetadataNonPojoImpl implements BytecodeEnhanceme } @Override - public LazyAttributeLoadingInterceptor extractInterceptor(Object entity) throws NotInstrumentedException { + public @Nullable LazyAttributeLoadingInterceptor extractInterceptor(Object entity) throws NotInstrumentedException { throw new NotInstrumentedException( errorMsg ); } @Override - public BytecodeLazyAttributeInterceptor extractLazyInterceptor(Object entity) throws NotInstrumentedException { + public @Nullable BytecodeLazyAttributeInterceptor extractLazyInterceptor(Object entity) throws NotInstrumentedException { throw new NotInstrumentedException( errorMsg ); } diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/BytecodeEnhancementMetadataPojoImpl.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/BytecodeEnhancementMetadataPojoImpl.java index 15c0ef57e4..148ad7093b 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/BytecodeEnhancementMetadataPojoImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/BytecodeEnhancementMetadataPojoImpl.java @@ -27,6 +27,8 @@ import org.hibernate.mapping.PersistentClass; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.type.CompositeType; +import org.checkerframework.checker.nullness.qual.Nullable; + import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable; import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptableType; import static org.hibernate.engine.internal.ManagedTypeHelper.processIfSelfDirtinessTracker; @@ -136,7 +138,7 @@ public final class BytecodeEnhancementMetadataPojoImpl implements BytecodeEnhanc } @Override - public LazyAttributeLoadingInterceptor extractInterceptor(Object entity) throws NotInstrumentedException { + public @Nullable LazyAttributeLoadingInterceptor extractInterceptor(Object entity) throws NotInstrumentedException { return (LazyAttributeLoadingInterceptor) extractLazyInterceptor( entity ); } @@ -257,7 +259,7 @@ public final class BytecodeEnhancementMetadataPojoImpl implements BytecodeEnhanc } @Override - public BytecodeLazyAttributeInterceptor extractLazyInterceptor(Object entity) throws NotInstrumentedException { + public @Nullable BytecodeLazyAttributeInterceptor extractLazyInterceptor(Object entity) throws NotInstrumentedException { if ( !enhancedForLazyLoading ) { throw new NotInstrumentedException( "Entity class [" + entityClass.getName() + "] is not enhanced for lazy loading" ); } diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java index a560dcb076..ab49b93f11 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java @@ -67,6 +67,7 @@ import net.bytebuddy.jar.asm.Opcodes; import net.bytebuddy.jar.asm.Type; import net.bytebuddy.matcher.ElementMatcher; import net.bytebuddy.matcher.ElementMatchers; +import org.checkerframework.checker.nullness.qual.Nullable; public class BytecodeProviderImpl implements BytecodeProvider { @@ -198,7 +199,7 @@ public class BytecodeProviderImpl implements BytecodeProvider { } @Override - public ReflectionOptimizer getReflectionOptimizer(Class clazz, Map propertyAccessMap) { + public @Nullable ReflectionOptimizer getReflectionOptimizer(Class clazz, Map propertyAccessMap) { final Class fastClass; if ( !clazz.isInterface() && !Modifier.isAbstract( clazz.getModifiers() ) ) { // we only provide a fast class instantiator if the class can be instantiated @@ -1313,7 +1314,7 @@ public class BytecodeProviderImpl implements BytecodeProvider { } @Override - public Enhancer getEnhancer(EnhancementContext enhancementContext) { + public @Nullable Enhancer getEnhancer(EnhancementContext enhancementContext) { return new EnhancerImpl( enhancementContext, byteBuddyState ); } diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/none/BytecodeProviderImpl.java b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/none/BytecodeProviderImpl.java index d389f1fd58..1446874229 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/internal/none/BytecodeProviderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/internal/none/BytecodeProviderImpl.java @@ -17,6 +17,8 @@ import org.hibernate.bytecode.spi.ReflectionOptimizer; import org.hibernate.cfg.AvailableSettings; import org.hibernate.property.access.spi.PropertyAccess; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * This BytecodeProvider represents the "no-op" enhancer; mostly useful * as an optimisation when not needing any byte code optimisation applied, @@ -44,12 +46,12 @@ public final class BytecodeProviderImpl implements BytecodeProvider { } @Override - public ReflectionOptimizer getReflectionOptimizer(Class clazz, Map propertyAccessMap) { + public @Nullable ReflectionOptimizer getReflectionOptimizer(Class clazz, Map propertyAccessMap) { throw new HibernateException( "Using the ReflectionOptimizer is not possible when the configured BytecodeProvider is 'none'. Disable " + AvailableSettings.USE_REFLECTION_OPTIMIZER + " or use a different BytecodeProvider"); } @Override - public Enhancer getEnhancer(EnhancementContext enhancementContext) { + public @Nullable Enhancer getEnhancer(EnhancementContext enhancementContext) { return null; } } diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/spi/BytecodeEnhancementMetadata.java b/hibernate-core/src/main/java/org/hibernate/bytecode/spi/BytecodeEnhancementMetadata.java index deecb83f9f..55cfb0e5a7 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/spi/BytecodeEnhancementMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/spi/BytecodeEnhancementMetadata.java @@ -14,6 +14,8 @@ import org.hibernate.engine.spi.PersistentAttributeInterceptable; import org.hibernate.engine.spi.PersistentAttributeInterceptor; import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * Encapsulates bytecode enhancement information about a particular entity. * @@ -80,9 +82,9 @@ public interface BytecodeEnhancementMetadata { * * @throws NotInstrumentedException Thrown if {@link #isEnhancedForLazyLoading()} returns {@code false} */ - LazyAttributeLoadingInterceptor extractInterceptor(Object entity) throws NotInstrumentedException; + @Nullable LazyAttributeLoadingInterceptor extractInterceptor(Object entity) throws NotInstrumentedException; - BytecodeLazyAttributeInterceptor extractLazyInterceptor(Object entity) throws NotInstrumentedException; + @Nullable BytecodeLazyAttributeInterceptor extractLazyInterceptor(Object entity) throws NotInstrumentedException; boolean hasUnFetchedAttributes(Object entity); diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/spi/BytecodeProvider.java b/hibernate-core/src/main/java/org/hibernate/bytecode/spi/BytecodeProvider.java index 3b33864673..2b9c336535 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/spi/BytecodeProvider.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/spi/BytecodeProvider.java @@ -13,6 +13,8 @@ import org.hibernate.bytecode.enhance.spi.Enhancer; import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.service.Service; +import org.checkerframework.checker.nullness.qual.Nullable; + /** * Contract for providers of bytecode services to Hibernate. *

@@ -54,7 +56,7 @@ public interface BytecodeProvider extends Service { * @param propertyAccessMap The ordered property access map * @return The reflection optimization delegate. */ - ReflectionOptimizer getReflectionOptimizer(Class clazz, Map propertyAccessMap); + @Nullable ReflectionOptimizer getReflectionOptimizer(Class clazz, Map propertyAccessMap); /** * Returns a byte code enhancer that implements the enhancements described in the supplied enhancement context. @@ -63,7 +65,7 @@ public interface BytecodeProvider extends Service { * * @return An enhancer to perform byte code manipulations. */ - Enhancer getEnhancer(EnhancementContext enhancementContext); + @Nullable Enhancer getEnhancer(EnhancementContext enhancementContext); /** * Some BytecodeProvider implementations will have classloader specific caching. diff --git a/hibernate-core/src/main/java/org/hibernate/bytecode/spi/ClassTransformer.java b/hibernate-core/src/main/java/org/hibernate/bytecode/spi/ClassTransformer.java index b198a11cda..49d2ef494a 100644 --- a/hibernate-core/src/main/java/org/hibernate/bytecode/spi/ClassTransformer.java +++ b/hibernate-core/src/main/java/org/hibernate/bytecode/spi/ClassTransformer.java @@ -9,6 +9,7 @@ package org.hibernate.bytecode.spi; import java.security.ProtectionDomain; import jakarta.persistence.spi.TransformerException; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A persistence provider provides an instance of this interface to the @@ -36,9 +37,9 @@ public interface ClassTransformer extends jakarta.persistence.spi.ClassTransform */ @Override byte[] transform( - ClassLoader loader, + @Nullable ClassLoader loader, String className, - Class classBeingRedefined, + @Nullable Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws TransformerException; }