HHH-16515 - Add @nullable annotations to org.hibernate.action.spi

HHH-16515 - Add the org.hibernate.context.spi package to nullness checking
HHH-16515 - Add the org.hibernate.bytecode.spi package to nullness checking

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
Jan Schatteman 2023-04-26 18:27:28 +02:00 committed by Jan Schatteman
parent a92566a94d
commit 6844ed07b2
9 changed files with 31 additions and 17 deletions

View File

@ -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)\\.'
]
}

View File

@ -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

View File

@ -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 );
}

View File

@ -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" );
}

View File

@ -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<String, PropertyAccess> propertyAccessMap) {
public @Nullable ReflectionOptimizer getReflectionOptimizer(Class<?> clazz, Map<String, PropertyAccess> 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 );
}

View File

@ -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<String, PropertyAccess> propertyAccessMap) {
public @Nullable ReflectionOptimizer getReflectionOptimizer(Class<?> clazz, Map<String, PropertyAccess> 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;
}
}

View File

@ -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);

View File

@ -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.
* <p>
@ -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<String, PropertyAccess> propertyAccessMap);
@Nullable ReflectionOptimizer getReflectionOptimizer(Class<?> clazz, Map<String, PropertyAccess> 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.

View File

@ -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;
}