Switch to JSpecify annotations

This commit updates the whole Spring Framework codebase to use JSpecify
annotations instead of Spring null-safety annotations with JSR 305
semantics.

JSpecify provides signficant enhancements such as properly defined
specifications, a canonical dependency with no split-package issue,
better tooling, better Kotlin integration and the capability to specify
generic type, array and varargs element null-safety. Generic type
null-safety is not defined by this commit yet and will be specified
later.

A key difference is that Spring null-safety annotations, following
JSR 305 semantics, apply to fields, parameters and return values,
while JSpecify annotations apply to type usages. That's why this
commit moves nullability annotations closer to the type for fields
and return values.

See gh-28797
This commit is contained in:
Sébastien Deleuze
2024-12-03 15:22:37 +01:00
parent fcb8aed03f
commit bc5d771a06
3459 changed files with 14118 additions and 22059 deletions

View File

@@ -16,8 +16,9 @@
package org.springframework.orm;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.lang.Nullable;
/**
* Exception thrown on an optimistic locking violation for a mapped object.
@@ -29,11 +30,9 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class ObjectOptimisticLockingFailureException extends OptimisticLockingFailureException {
@Nullable
private final Object persistentClass;
private final @Nullable Object persistentClass;
@Nullable
private final Object identifier;
private final @Nullable Object identifier;
/**
@@ -135,8 +134,7 @@ public class ObjectOptimisticLockingFailureException extends OptimisticLockingFa
* Return the persistent class of the object for which the locking failed.
* If no Class was specified, this method returns null.
*/
@Nullable
public Class<?> getPersistentClass() {
public @Nullable Class<?> getPersistentClass() {
return (this.persistentClass instanceof Class<?> clazz ? clazz : null);
}
@@ -144,8 +142,7 @@ public class ObjectOptimisticLockingFailureException extends OptimisticLockingFa
* Return the name of the persistent class of the object for which the locking failed.
* Will work for both Class objects and String names.
*/
@Nullable
public String getPersistentClassName() {
public @Nullable String getPersistentClassName() {
if (this.persistentClass instanceof Class<?> clazz) {
return clazz.getName();
}
@@ -155,8 +152,7 @@ public class ObjectOptimisticLockingFailureException extends OptimisticLockingFa
/**
* Return the identifier of the object for which the locking failed.
*/
@Nullable
public Object getIdentifier() {
public @Nullable Object getIdentifier() {
return this.identifier;
}

View File

@@ -16,8 +16,9 @@
package org.springframework.orm;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataRetrievalFailureException;
import org.springframework.lang.Nullable;
/**
* Exception thrown if a mapped object could not be retrieved via its identifier.
@@ -29,11 +30,9 @@ import org.springframework.lang.Nullable;
@SuppressWarnings("serial")
public class ObjectRetrievalFailureException extends DataRetrievalFailureException {
@Nullable
private final Object persistentClass;
private final @Nullable Object persistentClass;
@Nullable
private final Object identifier;
private final @Nullable Object identifier;
/**
@@ -109,8 +108,7 @@ public class ObjectRetrievalFailureException extends DataRetrievalFailureExcepti
* Return the persistent class of the object that was not found.
* If no Class was specified, this method returns null.
*/
@Nullable
public Class<?> getPersistentClass() {
public @Nullable Class<?> getPersistentClass() {
return (this.persistentClass instanceof Class<?> clazz ? clazz : null);
}
@@ -118,8 +116,7 @@ public class ObjectRetrievalFailureException extends DataRetrievalFailureExcepti
* Return the name of the persistent class of the object that was not found.
* Will work for both Class objects and String names.
*/
@Nullable
public String getPersistentClassName() {
public @Nullable String getPersistentClassName() {
if (this.persistentClass instanceof Class<?> clazz) {
return clazz.getName();
}
@@ -129,8 +126,7 @@ public class ObjectRetrievalFailureException extends DataRetrievalFailureExcepti
/**
* Return the identifier of the object that was not found.
*/
@Nullable
public Object getIdentifier() {
public @Nullable Object getIdentifier() {
return this.identifier;
}

View File

@@ -25,8 +25,8 @@ import jakarta.transaction.TransactionSynchronizationRegistry;
import jakarta.transaction.UserTransaction;
import org.hibernate.TransactionException;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.transaction.jta.UserTransactionAdapter;
import org.springframework.util.Assert;
@@ -44,8 +44,7 @@ class ConfigurableJtaPlatform implements JtaPlatform {
private final UserTransaction userTransaction;
@Nullable
private final TransactionSynchronizationRegistry transactionSynchronizationRegistry;
private final @Nullable TransactionSynchronizationRegistry transactionSynchronizationRegistry;
/**

View File

@@ -19,11 +19,11 @@ package org.springframework.orm.hibernate5;
import jakarta.persistence.PersistenceException;
import org.hibernate.HibernateException;
import org.hibernate.JDBCException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.jdbc.support.SQLExceptionTranslator;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.EntityManagerFactoryUtils;
/**
@@ -45,8 +45,7 @@ import org.springframework.orm.jpa.EntityManagerFactoryUtils;
*/
public class HibernateExceptionTranslator implements PersistenceExceptionTranslator {
@Nullable
private SQLExceptionTranslator jdbcExceptionTranslator;
private @Nullable SQLExceptionTranslator jdbcExceptionTranslator;
/**
@@ -66,8 +65,7 @@ public class HibernateExceptionTranslator implements PersistenceExceptionTransla
@Override
@Nullable
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
public @Nullable DataAccessException translateExceptionIfPossible(RuntimeException ex) {
if (ex instanceof HibernateException hibernateEx) {
return convertHibernateAccessException(hibernateEx);
}

View File

@@ -19,9 +19,9 @@ package org.springframework.orm.hibernate5;
import java.sql.SQLException;
import org.hibernate.JDBCException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.UncategorizedDataAccessException;
import org.springframework.lang.Nullable;
/**
* Hibernate-specific subclass of UncategorizedDataAccessException,
@@ -50,9 +50,8 @@ public class HibernateJdbcException extends UncategorizedDataAccessException {
/**
* Return the SQL that led to the problem.
*/
@Nullable
@SuppressWarnings("NullAway")
public String getSql() {
public @Nullable String getSql() {
return ((JDBCException) getCause()).getSQL();
}

View File

@@ -17,9 +17,9 @@
package org.springframework.orm.hibernate5;
import org.hibernate.QueryException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.lang.Nullable;
/**
* Hibernate-specific subclass of InvalidDataAccessResourceUsageException,
@@ -39,9 +39,8 @@ public class HibernateQueryException extends InvalidDataAccessResourceUsageExcep
/**
* Return the HQL query string that was invalid.
*/
@Nullable
@SuppressWarnings("NullAway")
public String getQueryString() {
public @Nullable String getQueryString() {
return ((QueryException) getCause()).getQueryString();
}

View File

@@ -17,9 +17,9 @@
package org.springframework.orm.hibernate5;
import org.hibernate.HibernateException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.UncategorizedDataAccessException;
import org.springframework.lang.Nullable;
/**
* Hibernate-specific subclass of UncategorizedDataAccessException,

View File

@@ -32,6 +32,7 @@ import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
@@ -43,7 +44,6 @@ import org.springframework.jdbc.datasource.ConnectionHolder;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.jdbc.datasource.JdbcTransactionObjectSupport;
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
import org.springframework.lang.Nullable;
import org.springframework.transaction.CannotCreateTransactionException;
import org.springframework.transaction.IllegalTransactionStateException;
import org.springframework.transaction.InvalidIsolationLevelException;
@@ -114,11 +114,9 @@ import org.springframework.util.Assert;
public class HibernateTransactionManager extends AbstractPlatformTransactionManager
implements ResourceTransactionManager, BeanFactoryAware, InitializingBean {
@Nullable
private SessionFactory sessionFactory;
private @Nullable SessionFactory sessionFactory;
@Nullable
private DataSource dataSource;
private @Nullable DataSource dataSource;
private boolean autodetectDataSource = true;
@@ -128,18 +126,15 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
private boolean hibernateManagedSession = false;
@Nullable
private Consumer<Session> sessionInitializer;
private @Nullable Consumer<Session> sessionInitializer;
@Nullable
private Object entityInterceptor;
private @Nullable Object entityInterceptor;
/**
* Just needed for entityInterceptorBeanName.
* @see #setEntityInterceptorBeanName
*/
@Nullable
private BeanFactory beanFactory;
private @Nullable BeanFactory beanFactory;
/**
@@ -170,8 +165,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
/**
* Return the SessionFactory that this instance should manage transactions for.
*/
@Nullable
public SessionFactory getSessionFactory() {
public @Nullable SessionFactory getSessionFactory() {
return this.sessionFactory;
}
@@ -231,8 +225,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
/**
* Return the JDBC DataSource that this instance manages transactions for.
*/
@Nullable
public DataSource getDataSource() {
public @Nullable DataSource getDataSource() {
return this.dataSource;
}
@@ -363,8 +356,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
* @see #setEntityInterceptorBeanName
* @see #setBeanFactory
*/
@Nullable
public Interceptor getEntityInterceptor() throws IllegalStateException, BeansException {
public @Nullable Interceptor getEntityInterceptor() throws IllegalStateException, BeansException {
if (this.entityInterceptor instanceof Interceptor interceptor) {
return interceptor;
}
@@ -799,8 +791,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
*/
private class HibernateTransactionObject extends JdbcTransactionObjectSupport {
@Nullable
private SessionHolder sessionHolder;
private @Nullable SessionHolder sessionHolder;
private boolean newSessionHolder;
@@ -808,8 +799,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
private boolean needsConnectionReset;
@Nullable
private Integer previousHoldability;
private @Nullable Integer previousHoldability;
public void setSession(Session session) {
this.sessionHolder = new SessionHolder(session);
@@ -858,8 +848,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
this.previousHoldability = previousHoldability;
}
@Nullable
public Integer getPreviousHoldability() {
public @Nullable Integer getPreviousHoldability() {
return this.previousHoldability;
}
@@ -911,8 +900,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
private final SessionHolder sessionHolder;
@Nullable
private final ConnectionHolder connectionHolder;
private final @Nullable ConnectionHolder connectionHolder;
private SuspendedResourcesHolder(SessionHolder sessionHolder, @Nullable ConnectionHolder conHolder) {
this.sessionHolder = sessionHolder;
@@ -923,8 +911,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana
return this.sessionHolder;
}
@Nullable
private ConnectionHolder getConnectionHolder() {
private @Nullable ConnectionHolder getConnectionHolder() {
return this.connectionHolder;
}
}

View File

@@ -34,6 +34,7 @@ import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.service.ServiceRegistry;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
@@ -52,7 +53,6 @@ import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternUtils;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.lang.Nullable;
/**
* {@link FactoryBean} that creates a Hibernate {@link SessionFactory}. This is the usual
@@ -84,85 +84,59 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator
implements FactoryBean<SessionFactory>, ResourceLoaderAware, BeanFactoryAware,
InitializingBean, SmartInitializingSingleton, DisposableBean {
@Nullable
private DataSource dataSource;
private @Nullable DataSource dataSource;
@Nullable
private Resource[] configLocations;
private Resource @Nullable [] configLocations;
@Nullable
private String[] mappingResources;
private String @Nullable [] mappingResources;
@Nullable
private Resource[] mappingLocations;
private Resource @Nullable [] mappingLocations;
@Nullable
private Resource[] cacheableMappingLocations;
private Resource @Nullable [] cacheableMappingLocations;
@Nullable
private Resource[] mappingJarLocations;
private Resource @Nullable [] mappingJarLocations;
@Nullable
private Resource[] mappingDirectoryLocations;
private Resource @Nullable [] mappingDirectoryLocations;
@Nullable
private Interceptor entityInterceptor;
private @Nullable Interceptor entityInterceptor;
@Nullable
private ImplicitNamingStrategy implicitNamingStrategy;
private @Nullable ImplicitNamingStrategy implicitNamingStrategy;
@Nullable
private PhysicalNamingStrategy physicalNamingStrategy;
private @Nullable PhysicalNamingStrategy physicalNamingStrategy;
@Nullable
private Object jtaTransactionManager;
private @Nullable Object jtaTransactionManager;
@Nullable
private RegionFactory cacheRegionFactory;
private @Nullable RegionFactory cacheRegionFactory;
@Nullable
private MultiTenantConnectionProvider<?> multiTenantConnectionProvider;
private @Nullable MultiTenantConnectionProvider<?> multiTenantConnectionProvider;
@Nullable
private CurrentTenantIdentifierResolver<Object> currentTenantIdentifierResolver;
private @Nullable CurrentTenantIdentifierResolver<Object> currentTenantIdentifierResolver;
@Nullable
private Properties hibernateProperties;
private @Nullable Properties hibernateProperties;
@Nullable
private TypeFilter[] entityTypeFilters;
private TypeFilter @Nullable [] entityTypeFilters;
@Nullable
private Class<?>[] annotatedClasses;
private Class<?> @Nullable [] annotatedClasses;
@Nullable
private String[] annotatedPackages;
private String @Nullable [] annotatedPackages;
@Nullable
private String[] packagesToScan;
private String @Nullable [] packagesToScan;
@Nullable
private AsyncTaskExecutor bootstrapExecutor;
private @Nullable AsyncTaskExecutor bootstrapExecutor;
@Nullable
private Integrator[] hibernateIntegrators;
private Integrator @Nullable [] hibernateIntegrators;
private boolean metadataSourcesAccessed = false;
@Nullable
private MetadataSources metadataSources;
private @Nullable MetadataSources metadataSources;
@Nullable
private ResourcePatternResolver resourcePatternResolver;
private @Nullable ResourcePatternResolver resourcePatternResolver;
@Nullable
private ConfigurableListableBeanFactory beanFactory;
private @Nullable ConfigurableListableBeanFactory beanFactory;
@Nullable
private Configuration configuration;
private @Nullable Configuration configuration;
@Nullable
private SessionFactory sessionFactory;
private @Nullable SessionFactory sessionFactory;
/**
@@ -643,8 +617,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator
@Override
@Nullable
public SessionFactory getObject() {
public @Nullable SessionFactory getObject() {
return this.sessionFactory;
}

View File

@@ -49,6 +49,7 @@ import org.hibernate.context.spi.CurrentTenantIdentifierResolver;
import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.InfrastructureProxy;
@@ -65,7 +66,6 @@ import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.lang.Nullable;
import org.springframework.transaction.jta.JtaTransactionManager;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -120,8 +120,7 @@ public class LocalSessionFactoryBuilder extends Configuration {
private final ResourcePatternResolver resourcePatternResolver;
@Nullable
private TypeFilter[] entityTypeFilters = DEFAULT_ENTITY_TYPE_FILTERS;
private @Nullable TypeFilter[] entityTypeFilters = DEFAULT_ENTITY_TYPE_FILTERS;
/**

View File

@@ -51,6 +51,7 @@ import org.hibernate.exception.JDBCConnectionException;
import org.hibernate.exception.LockAcquisitionException;
import org.hibernate.exception.SQLGrammarException;
import org.hibernate.service.UnknownServiceException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.dao.DataAccessException;
@@ -62,7 +63,6 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.dao.PessimisticLockingFailureException;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.lang.Nullable;
/**
* Helper class featuring methods for Hibernate Session handling.
@@ -146,8 +146,7 @@ public abstract class SessionFactoryUtils {
* @return the DataSource, or {@code null} if none found
* @see ConnectionProvider
*/
@Nullable
public static DataSource getDataSource(SessionFactory sessionFactory) {
public static @Nullable DataSource getDataSource(SessionFactory sessionFactory) {
Map<String, Object> props = sessionFactory.getProperties();
if (props != null) {
Object dataSourceValue = props.get(Environment.JAKARTA_NON_JTA_DATASOURCE);

View File

@@ -19,8 +19,8 @@ package org.springframework.orm.hibernate5;
import org.hibernate.FlushMode;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.EntityManagerHolder;
/**
@@ -38,11 +38,9 @@ import org.springframework.orm.jpa.EntityManagerHolder;
*/
public class SessionHolder extends EntityManagerHolder {
@Nullable
private Transaction transaction;
private @Nullable Transaction transaction;
@Nullable
private FlushMode previousFlushMode;
private @Nullable FlushMode previousFlushMode;
public SessionHolder(Session session) {
@@ -59,8 +57,7 @@ public class SessionHolder extends EntityManagerHolder {
setTransactionActive(transaction != null);
}
@Nullable
public Transaction getTransaction() {
public @Nullable Transaction getTransaction() {
return this.transaction;
}
@@ -68,8 +65,7 @@ public class SessionHolder extends EntityManagerHolder {
this.previousFlushMode = previousFlushMode;
}
@Nullable
public FlushMode getPreviousFlushMode() {
public @Nullable FlushMode getPreviousFlushMode() {
return this.previousFlushMode;
}

View File

@@ -25,12 +25,12 @@ import org.hibernate.resource.beans.container.spi.BeanContainer;
import org.hibernate.resource.beans.container.spi.ContainedBean;
import org.hibernate.resource.beans.spi.BeanInstanceProducer;
import org.hibernate.type.spi.TypeBootstrapContext;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap;
@@ -243,8 +243,7 @@ public final class SpringBeanContainer implements BeanContainer {
private final B beanInstance;
@Nullable
private Consumer<B> destructionCallback;
private @Nullable Consumer<B> destructionCallback;
public SpringContainedBean(B beanInstance) {
this.beanInstance = beanInstance;

View File

@@ -17,8 +17,8 @@
package org.springframework.orm.hibernate5;
import org.hibernate.Session;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.transaction.support.TransactionSynchronization;
/**

View File

@@ -26,8 +26,8 @@ import org.hibernate.Session;
import org.hibernate.context.spi.CurrentSessionContext;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.EntityManagerHolder;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -48,11 +48,9 @@ public class SpringSessionContext implements CurrentSessionContext {
private final SessionFactoryImplementor sessionFactory;
@Nullable
private TransactionManager transactionManager;
private @Nullable TransactionManager transactionManager;
@Nullable
private CurrentSessionContext jtaSessionContext;
private @Nullable CurrentSessionContext jtaSessionContext;
/**

View File

@@ -10,9 +10,7 @@
*
* <p><b>This package supports Hibernate 5.x only.</b>
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.orm.hibernate5;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -21,8 +21,8 @@ import java.util.concurrent.Callable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.SessionFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.orm.hibernate5.SessionFactoryUtils;
import org.springframework.orm.hibernate5.SessionHolder;
import org.springframework.transaction.support.TransactionSynchronizationManager;

View File

@@ -22,10 +22,10 @@ import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.lang.Nullable;
import org.springframework.orm.hibernate5.SessionFactoryUtils;
import org.springframework.orm.hibernate5.SessionHolder;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -80,8 +80,7 @@ public class OpenSessionInViewInterceptor implements AsyncWebRequestInterceptor
protected final Log logger = LogFactory.getLog(getClass());
@Nullable
private SessionFactory sessionFactory;
private @Nullable SessionFactory sessionFactory;
/**
@@ -94,8 +93,7 @@ public class OpenSessionInViewInterceptor implements AsyncWebRequestInterceptor
/**
* Return the Hibernate SessionFactory that should be used to create Hibernate Sessions.
*/
@Nullable
public SessionFactory getSessionFactory() {
public @Nullable SessionFactory getSessionFactory() {
return this.sessionFactory;
}

View File

@@ -22,10 +22,10 @@ import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.lang.Nullable;
import org.springframework.orm.hibernate5.SessionFactoryUtils;
import org.springframework.orm.hibernate5.SessionHolder;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -50,8 +50,7 @@ import org.springframework.util.Assert;
*/
public class OpenSessionInterceptor implements MethodInterceptor, InitializingBean {
@Nullable
private SessionFactory sessionFactory;
private @Nullable SessionFactory sessionFactory;
/**
@@ -64,8 +63,7 @@ public class OpenSessionInterceptor implements MethodInterceptor, InitializingBe
/**
* Return the Hibernate SessionFactory that should be used to create Hibernate Sessions.
*/
@Nullable
public SessionFactory getSessionFactory() {
public @Nullable SessionFactory getSessionFactory() {
return this.sessionFactory;
}
@@ -78,8 +76,7 @@ public class OpenSessionInterceptor implements MethodInterceptor, InitializingBe
@Override
@Nullable
public Object invoke(MethodInvocation invocation) throws Throwable {
public @Nullable Object invoke(MethodInvocation invocation) throws Throwable {
SessionFactory sf = getSessionFactory();
Assert.state(sf != null, "No SessionFactory set");

View File

@@ -1,9 +1,7 @@
/**
* Classes supporting the {@code org.springframework.orm.hibernate5} package.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.orm.hibernate5.support;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -45,6 +45,7 @@ import jakarta.persistence.spi.PersistenceProvider;
import jakarta.persistence.spi.PersistenceUnitInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.BeanClassLoaderAware;
@@ -58,7 +59,6 @@ import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -98,51 +98,38 @@ public abstract class AbstractEntityManagerFactoryBean implements
/** Logger available to subclasses. */
protected final Log logger = LogFactory.getLog(getClass());
@Nullable
private PersistenceProvider persistenceProvider;
private @Nullable PersistenceProvider persistenceProvider;
@Nullable
private String persistenceUnitName;
private @Nullable String persistenceUnitName;
private final Map<String, Object> jpaPropertyMap = new HashMap<>();
@Nullable
private Class<? extends EntityManagerFactory> entityManagerFactoryInterface;
private @Nullable Class<? extends EntityManagerFactory> entityManagerFactoryInterface;
@Nullable
private Class<? extends EntityManager> entityManagerInterface;
private @Nullable Class<? extends EntityManager> entityManagerInterface;
@Nullable
private JpaDialect jpaDialect;
private @Nullable JpaDialect jpaDialect;
@Nullable
private JpaVendorAdapter jpaVendorAdapter;
private @Nullable JpaVendorAdapter jpaVendorAdapter;
@Nullable
private Consumer<EntityManager> entityManagerInitializer;
private @Nullable Consumer<EntityManager> entityManagerInitializer;
@Nullable
private AsyncTaskExecutor bootstrapExecutor;
private @Nullable AsyncTaskExecutor bootstrapExecutor;
private ClassLoader beanClassLoader = getClass().getClassLoader();
@Nullable
private BeanFactory beanFactory;
private @Nullable BeanFactory beanFactory;
@Nullable
private String beanName;
private @Nullable String beanName;
/** Raw EntityManagerFactory as returned by the PersistenceProvider. */
@Nullable
private EntityManagerFactory nativeEntityManagerFactory;
private @Nullable EntityManagerFactory nativeEntityManagerFactory;
/** Future for lazily initializing raw target EntityManagerFactory. */
@Nullable
private Future<EntityManagerFactory> nativeEntityManagerFactoryFuture;
private @Nullable Future<EntityManagerFactory> nativeEntityManagerFactoryFuture;
/** Exposed client-level EntityManagerFactory proxy. */
@Nullable
private EntityManagerFactory entityManagerFactory;
private @Nullable EntityManagerFactory entityManagerFactory;
/**
@@ -172,8 +159,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
}
@Override
@Nullable
public PersistenceProvider getPersistenceProvider() {
public @Nullable PersistenceProvider getPersistenceProvider() {
return this.persistenceProvider;
}
@@ -189,8 +175,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
}
@Override
@Nullable
public String getPersistenceUnitName() {
public @Nullable String getPersistenceUnitName() {
return this.persistenceUnitName;
}
@@ -255,8 +240,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
}
@Override
@Nullable
public Class<? extends EntityManager> getEntityManagerInterface() {
public @Nullable Class<? extends EntityManager> getEntityManagerInterface() {
return this.entityManagerInterface;
}
@@ -272,8 +256,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
}
@Override
@Nullable
public JpaDialect getJpaDialect() {
public @Nullable JpaDialect getJpaDialect() {
return this.jpaDialect;
}
@@ -291,8 +274,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
* Return the JpaVendorAdapter implementation for this EntityManagerFactory,
* or {@code null} if not known.
*/
@Nullable
public JpaVendorAdapter getJpaVendorAdapter() {
public @Nullable JpaVendorAdapter getJpaVendorAdapter() {
return this.jpaVendorAdapter;
}
@@ -332,8 +314,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
* Return the asynchronous executor for background bootstrapping, if any.
* @since 4.3
*/
@Nullable
public AsyncTaskExecutor getBootstrapExecutor() {
public @Nullable AsyncTaskExecutor getBootstrapExecutor() {
return this.bootstrapExecutor;
}
@@ -492,7 +473,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
* Delegate an incoming invocation from the proxy, dispatching to EntityManagerFactoryInfo
* or the native EntityManagerFactory accordingly.
*/
Object invokeProxyMethod(Method method, @Nullable Object[] args) throws Throwable {
Object invokeProxyMethod(Method method, Object @Nullable [] args) throws Throwable {
if (method.getDeclaringClass().isAssignableFrom(EntityManagerFactoryInfo.class)) {
return method.invoke(this, args);
}
@@ -554,8 +535,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
* @see EntityManagerFactoryUtils#convertJpaAccessExceptionIfPossible
*/
@Override
@Nullable
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
public @Nullable DataAccessException translateExceptionIfPossible(RuntimeException ex) {
JpaDialect jpaDialect = getJpaDialect();
return (jpaDialect != null ? jpaDialect.translateExceptionIfPossible(ex) :
EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex));
@@ -618,14 +598,12 @@ public abstract class AbstractEntityManagerFactoryBean implements
}
@Override
@Nullable
public PersistenceUnitInfo getPersistenceUnitInfo() {
public @Nullable PersistenceUnitInfo getPersistenceUnitInfo() {
return null;
}
@Override
@Nullable
public DataSource getDataSource() {
public @Nullable DataSource getDataSource() {
return null;
}
@@ -634,8 +612,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
* Return the singleton EntityManagerFactory.
*/
@Override
@Nullable
public EntityManagerFactory getObject() {
public @Nullable EntityManagerFactory getObject() {
return this.entityManagerFactory;
}
@@ -719,8 +696,7 @@ public abstract class AbstractEntityManagerFactoryBean implements
}
@Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
switch (method.getName()) {
case "equals" -> {
// Only consider equal when proxies are identical.

View File

@@ -21,10 +21,10 @@ import java.sql.SQLException;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.datasource.ConnectionHandle;
import org.springframework.lang.Nullable;
import org.springframework.transaction.InvalidIsolationLevelException;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
@@ -56,8 +56,7 @@ public class DefaultJpaDialect implements JpaDialect, Serializable {
* @see #cleanupTransaction
*/
@Override
@Nullable
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
public @Nullable Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
throws PersistenceException, SQLException, TransactionException {
if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) {
@@ -70,8 +69,7 @@ public class DefaultJpaDialect implements JpaDialect, Serializable {
}
@Override
@Nullable
public Object prepareTransaction(EntityManager entityManager, boolean readOnly, @Nullable String name)
public @Nullable Object prepareTransaction(EntityManager entityManager, boolean readOnly, @Nullable String name)
throws PersistenceException {
return null;
@@ -91,8 +89,7 @@ public class DefaultJpaDialect implements JpaDialect, Serializable {
* indicating that no JDBC Connection can be provided.
*/
@Override
@Nullable
public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
public @Nullable ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
throws PersistenceException, SQLException {
return null;
@@ -121,8 +118,7 @@ public class DefaultJpaDialect implements JpaDialect, Serializable {
* @see EntityManagerFactoryUtils#convertJpaAccessExceptionIfPossible
*/
@Override
@Nullable
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
public @Nullable DataAccessException translateExceptionIfPossible(RuntimeException ex) {
return EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex);
}

View File

@@ -24,12 +24,12 @@ import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -46,11 +46,9 @@ public abstract class EntityManagerFactoryAccessor implements BeanFactoryAware {
/** Logger available to subclasses. */
protected final Log logger = LogFactory.getLog(getClass());
@Nullable
private EntityManagerFactory entityManagerFactory;
private @Nullable EntityManagerFactory entityManagerFactory;
@Nullable
private String persistenceUnitName;
private @Nullable String persistenceUnitName;
private final Map<String, Object> jpaPropertyMap = new HashMap<>();
@@ -69,8 +67,7 @@ public abstract class EntityManagerFactoryAccessor implements BeanFactoryAware {
* Return the JPA EntityManagerFactory that should be used to create
* EntityManagers.
*/
@Nullable
public EntityManagerFactory getEntityManagerFactory() {
public @Nullable EntityManagerFactory getEntityManagerFactory() {
return this.entityManagerFactory;
}
@@ -101,8 +98,7 @@ public abstract class EntityManagerFactoryAccessor implements BeanFactoryAware {
/**
* Return the name of the persistence unit to access the EntityManagerFactory for, if any.
*/
@Nullable
public String getPersistenceUnitName() {
public @Nullable String getPersistenceUnitName() {
return this.persistenceUnitName;
}
@@ -176,8 +172,7 @@ public abstract class EntityManagerFactoryAccessor implements BeanFactoryAware {
* @see EntityManagerFactoryUtils#getTransactionalEntityManager(jakarta.persistence.EntityManagerFactory)
* @see EntityManagerFactoryUtils#getTransactionalEntityManager(jakarta.persistence.EntityManagerFactory, java.util.Map)
*/
@Nullable
protected EntityManager getTransactionalEntityManager() throws IllegalStateException{
protected @Nullable EntityManager getTransactionalEntityManager() throws IllegalStateException{
EntityManagerFactory emf = obtainEntityManagerFactory();
return EntityManagerFactoryUtils.getTransactionalEntityManager(emf, getJpaPropertyMap());
}

View File

@@ -24,8 +24,7 @@ import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.spi.PersistenceProvider;
import jakarta.persistence.spi.PersistenceUnitInfo;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Metadata interface for a Spring-managed JPA {@link EntityManagerFactory}.
@@ -46,8 +45,7 @@ public interface EntityManagerFactoryInfo {
* or {@code null} if the standard JPA provider autodetection process
* was used to configure the EntityManagerFactory
*/
@Nullable
PersistenceProvider getPersistenceProvider();
@Nullable PersistenceProvider getPersistenceProvider();
/**
* Return the PersistenceUnitInfo used to create this
@@ -56,8 +54,7 @@ public interface EntityManagerFactoryInfo {
* or {@code null} if the in-container contract was not used to
* configure the EntityManagerFactory
*/
@Nullable
PersistenceUnitInfo getPersistenceUnitInfo();
@Nullable PersistenceUnitInfo getPersistenceUnitInfo();
/**
* Return the name of the persistence unit used to create this
@@ -68,16 +65,14 @@ public interface EntityManagerFactoryInfo {
* @see #getPersistenceUnitInfo()
* @see jakarta.persistence.spi.PersistenceUnitInfo#getPersistenceUnitName()
*/
@Nullable
String getPersistenceUnitName();
@Nullable String getPersistenceUnitName();
/**
* Return the JDBC DataSource that this EntityManagerFactory
* obtains its JDBC Connections from.
* @return the JDBC DataSource, or {@code null} if not known
*/
@Nullable
DataSource getDataSource();
@Nullable DataSource getDataSource();
/**
* Return the (potentially vendor-specific) EntityManager interface
@@ -86,15 +81,13 @@ public interface EntityManagerFactoryInfo {
* to happen: either based on a target {@code EntityManager} instance
* or simply defaulting to {@code jakarta.persistence.EntityManager}.
*/
@Nullable
Class<? extends EntityManager> getEntityManagerInterface();
@Nullable Class<? extends EntityManager> getEntityManagerInterface();
/**
* Return the vendor-specific JpaDialect implementation for this
* EntityManagerFactory, or {@code null} if not known.
*/
@Nullable
JpaDialect getJpaDialect();
@Nullable JpaDialect getJpaDialect();
/**
* Return the ClassLoader that the application's beans are loaded with.

View File

@@ -34,6 +34,7 @@ import jakarta.persistence.SynchronizationType;
import jakarta.persistence.TransactionRequiredException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.beans.factory.ListableBeanFactory;
@@ -48,7 +49,6 @@ import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.dao.PessimisticLockingFailureException;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.lang.Nullable;
import org.springframework.transaction.support.ResourceHolderSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.Assert;
@@ -130,8 +130,7 @@ public abstract class EntityManagerFactoryUtils {
* @throws DataAccessResourceFailureException if the EntityManager couldn't be obtained
* @see JpaTransactionManager
*/
@Nullable
public static EntityManager getTransactionalEntityManager(EntityManagerFactory emf)
public static @Nullable EntityManager getTransactionalEntityManager(EntityManagerFactory emf)
throws DataAccessResourceFailureException {
return getTransactionalEntityManager(emf, null);
@@ -148,8 +147,7 @@ public abstract class EntityManagerFactoryUtils {
* @throws DataAccessResourceFailureException if the EntityManager couldn't be obtained
* @see JpaTransactionManager
*/
@Nullable
public static EntityManager getTransactionalEntityManager(EntityManagerFactory emf, @Nullable Map<?, ?> properties)
public static @Nullable EntityManager getTransactionalEntityManager(EntityManagerFactory emf, @Nullable Map<?, ?> properties)
throws DataAccessResourceFailureException {
try {
return doGetTransactionalEntityManager(emf, properties, true);
@@ -171,8 +169,7 @@ public abstract class EntityManagerFactoryUtils {
* @see #getTransactionalEntityManager(jakarta.persistence.EntityManagerFactory)
* @see JpaTransactionManager
*/
@Nullable
public static EntityManager doGetTransactionalEntityManager(EntityManagerFactory emf, Map<?, ?> properties)
public static @Nullable EntityManager doGetTransactionalEntityManager(EntityManagerFactory emf, Map<?, ?> properties)
throws PersistenceException {
return doGetTransactionalEntityManager(emf, properties, true);
@@ -192,8 +189,7 @@ public abstract class EntityManagerFactoryUtils {
* @see #getTransactionalEntityManager(jakarta.persistence.EntityManagerFactory)
* @see JpaTransactionManager
*/
@Nullable
public static EntityManager doGetTransactionalEntityManager(
public static @Nullable EntityManager doGetTransactionalEntityManager(
EntityManagerFactory emf, @Nullable Map<?, ?> properties, boolean synchronizedWithTransaction)
throws PersistenceException {
@@ -300,8 +296,7 @@ public abstract class EntityManagerFactoryUtils {
* (to be passed into cleanupTransaction)
* @see JpaDialect#prepareTransaction
*/
@Nullable
private static Object prepareTransaction(EntityManager em, EntityManagerFactory emf) {
private static @Nullable Object prepareTransaction(EntityManager em, EntityManagerFactory emf) {
if (emf instanceof EntityManagerFactoryInfo emfInfo) {
JpaDialect jpaDialect = emfInfo.getJpaDialect();
if (jpaDialect != null) {
@@ -360,8 +355,7 @@ public abstract class EntityManagerFactoryUtils {
* @return the corresponding DataAccessException instance,
* or {@code null} if the exception should not be translated
*/
@Nullable
public static DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) {
public static @Nullable DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) {
// Following the JPA specification, a persistence provider can also
// throw these two exceptions, besides PersistenceException.
if (ex instanceof IllegalStateException) {
@@ -441,11 +435,9 @@ public abstract class EntityManagerFactoryUtils {
extends ResourceHolderSynchronization<EntityManagerHolder, EntityManagerFactory>
implements Ordered {
@Nullable
private final Object transactionData;
private final @Nullable Object transactionData;
@Nullable
private final JpaDialect jpaDialect;
private final @Nullable JpaDialect jpaDialect;
private final boolean newEntityManager;

View File

@@ -17,8 +17,8 @@
package org.springframework.orm.jpa;
import jakarta.persistence.EntityManager;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.transaction.SavepointManager;
import org.springframework.transaction.support.ResourceHolderSupport;
import org.springframework.util.Assert;
@@ -40,13 +40,11 @@ import org.springframework.util.Assert;
*/
public class EntityManagerHolder extends ResourceHolderSupport {
@Nullable
private final EntityManager entityManager;
private final @Nullable EntityManager entityManager;
private boolean transactionActive;
@Nullable
private SavepointManager savepointManager;
private @Nullable SavepointManager savepointManager;
public EntityManagerHolder(@Nullable EntityManager entityManager) {
@@ -71,8 +69,7 @@ public class EntityManagerHolder extends ResourceHolderSupport {
this.savepointManager = savepointManager;
}
@Nullable
protected SavepointManager getSavepointManager() {
protected @Nullable SavepointManager getSavepointManager() {
return this.savepointManager;
}

View File

@@ -18,11 +18,12 @@ package org.springframework.orm.jpa;
import java.util.Collections;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.hint.ExecutableMode;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.aot.hint.TypeReference;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
/**

View File

@@ -33,11 +33,11 @@ import jakarta.persistence.spi.PersistenceUnitInfo;
import jakarta.persistence.spi.PersistenceUnitTransactionType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.core.Ordered;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.lang.Nullable;
import org.springframework.transaction.support.ResourceHolderSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.Assert;
@@ -261,8 +261,7 @@ public abstract class ExtendedEntityManagerCreator {
private final EntityManager target;
@Nullable
private final PersistenceExceptionTranslator exceptionTranslator;
private final @Nullable PersistenceExceptionTranslator exceptionTranslator;
private final boolean jta;
@@ -293,8 +292,7 @@ public abstract class ExtendedEntityManagerCreator {
}
@Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// Invocation on EntityManager interface coming in...
switch (method.getName()) {
@@ -439,8 +437,7 @@ public abstract class ExtendedEntityManagerCreator {
private final EntityManager entityManager;
@Nullable
private final PersistenceExceptionTranslator exceptionTranslator;
private final @Nullable PersistenceExceptionTranslator exceptionTranslator;
public volatile boolean closeOnCompletion;

View File

@@ -20,10 +20,10 @@ import java.sql.SQLException;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.jdbc.datasource.ConnectionHandle;
import org.springframework.lang.Nullable;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
@@ -80,8 +80,7 @@ public interface JpaDialect extends PersistenceExceptionTranslator {
* @see jakarta.persistence.EntityTransaction#begin
* @see org.springframework.jdbc.datasource.DataSourceUtils#prepareConnectionForTransaction
*/
@Nullable
Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
@Nullable Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
throws PersistenceException, SQLException, TransactionException;
/**
@@ -103,8 +102,7 @@ public interface JpaDialect extends PersistenceExceptionTranslator {
* @throws jakarta.persistence.PersistenceException if thrown by JPA methods
* @see #cleanupTransaction
*/
@Nullable
Object prepareTransaction(EntityManager entityManager, boolean readOnly, @Nullable String name)
@Nullable Object prepareTransaction(EntityManager entityManager, boolean readOnly, @Nullable String name)
throws PersistenceException;
/**
@@ -150,8 +148,7 @@ public interface JpaDialect extends PersistenceExceptionTranslator {
* @see org.springframework.jdbc.datasource.SimpleConnectionHandle
* @see JpaTransactionManager#setDataSource
*/
@Nullable
ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
@Nullable ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly)
throws PersistenceException, SQLException;
/**

View File

@@ -28,6 +28,7 @@ import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.EntityTransaction;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.RollbackException;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
@@ -40,7 +41,6 @@ import org.springframework.jdbc.datasource.ConnectionHandle;
import org.springframework.jdbc.datasource.ConnectionHolder;
import org.springframework.jdbc.datasource.JdbcTransactionObjectSupport;
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
import org.springframework.lang.Nullable;
import org.springframework.transaction.CannotCreateTransactionException;
import org.springframework.transaction.IllegalTransactionStateException;
import org.springframework.transaction.NestedTransactionNotSupportedException;
@@ -117,21 +117,17 @@ import org.springframework.util.CollectionUtils;
public class JpaTransactionManager extends AbstractPlatformTransactionManager
implements ResourceTransactionManager, BeanFactoryAware, InitializingBean {
@Nullable
private EntityManagerFactory entityManagerFactory;
private @Nullable EntityManagerFactory entityManagerFactory;
@Nullable
private String persistenceUnitName;
private @Nullable String persistenceUnitName;
private final Map<String, Object> jpaPropertyMap = new HashMap<>();
@Nullable
private DataSource dataSource;
private @Nullable DataSource dataSource;
private JpaDialect jpaDialect = new DefaultJpaDialect();
@Nullable
private Consumer<EntityManager> entityManagerInitializer;
private @Nullable Consumer<EntityManager> entityManagerInitializer;
/**
@@ -168,8 +164,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
/**
* Return the EntityManagerFactory that this instance should manage transactions for.
*/
@Nullable
public EntityManagerFactory getEntityManagerFactory() {
public @Nullable EntityManagerFactory getEntityManagerFactory() {
return this.entityManagerFactory;
}
@@ -200,8 +195,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
/**
* Return the name of the persistence unit to manage transactions for, if any.
*/
@Nullable
public String getPersistenceUnitName() {
public @Nullable String getPersistenceUnitName() {
return this.persistenceUnitName;
}
@@ -276,8 +270,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
/**
* Return the JDBC DataSource that this instance manages transactions for.
*/
@Nullable
public DataSource getDataSource() {
public @Nullable DataSource getDataSource() {
return this.dataSource;
}
@@ -665,13 +658,11 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
*/
private class JpaTransactionObject extends JdbcTransactionObjectSupport {
@Nullable
private EntityManagerHolder entityManagerHolder;
private @Nullable EntityManagerHolder entityManagerHolder;
private boolean newEntityManagerHolder;
@Nullable
private Object transactionData;
private @Nullable Object transactionData;
public void setEntityManagerHolder(
@Nullable EntityManagerHolder entityManagerHolder, boolean newEntityManagerHolder) {
@@ -705,8 +696,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
}
}
@Nullable
public Object getTransactionData() {
public @Nullable Object getTransactionData() {
return this.transactionData;
}
@@ -808,8 +798,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
private final EntityManagerHolder entityManagerHolder;
@Nullable
private final ConnectionHolder connectionHolder;
private final @Nullable ConnectionHolder connectionHolder;
private SuspendedResourcesHolder(EntityManagerHolder emHolder, @Nullable ConnectionHolder conHolder) {
this.entityManagerHolder = emHolder;
@@ -820,8 +809,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager
return this.entityManagerHolder;
}
@Nullable
private ConnectionHolder getConnectionHolder() {
private @Nullable ConnectionHolder getConnectionHolder() {
return this.connectionHolder;
}
}

View File

@@ -23,8 +23,7 @@ import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.spi.PersistenceProvider;
import jakarta.persistence.spi.PersistenceUnitInfo;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* SPI interface that allows to plug in vendor-specific behavior
@@ -49,8 +48,7 @@ public interface JpaVendorAdapter {
* excluding provider classes from temporary class overriding.
* @since 2.5.2
*/
@Nullable
default String getPersistenceProviderRootPackage() {
default @Nullable String getPersistenceProviderRootPackage() {
return null;
}
@@ -99,8 +97,7 @@ public interface JpaVendorAdapter {
* Return the vendor-specific JpaDialect implementation for this
* provider, or {@code null} if there is none.
*/
@Nullable
default JpaDialect getJpaDialect() {
default @Nullable JpaDialect getJpaDialect() {
return null;
}

View File

@@ -24,6 +24,7 @@ import jakarta.persistence.SharedCacheMode;
import jakarta.persistence.ValidationMode;
import jakarta.persistence.spi.PersistenceProvider;
import jakarta.persistence.spi.PersistenceUnitInfo;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.context.ResourceLoaderAware;
@@ -31,7 +32,6 @@ import org.springframework.context.weaving.LoadTimeWeaverAware;
import org.springframework.core.io.ResourceLoader;
import org.springframework.instrument.classloading.LoadTimeWeaver;
import org.springframework.jdbc.datasource.lookup.SingleDataSourceLookup;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager;
import org.springframework.orm.jpa.persistenceunit.ManagedClassNameFilter;
import org.springframework.orm.jpa.persistenceunit.PersistenceManagedTypes;
@@ -89,13 +89,11 @@ import org.springframework.util.ClassUtils;
public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManagerFactoryBean
implements ResourceLoaderAware, LoadTimeWeaverAware {
@Nullable
private PersistenceUnitManager persistenceUnitManager;
private @Nullable PersistenceUnitManager persistenceUnitManager;
private final DefaultPersistenceUnitManager internalPersistenceUnitManager = new DefaultPersistenceUnitManager();
@Nullable
private PersistenceUnitInfo persistenceUnitInfo;
private @Nullable PersistenceUnitInfo persistenceUnitInfo;
/**
@@ -426,14 +424,12 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
@Override
@Nullable
public PersistenceUnitInfo getPersistenceUnitInfo() {
public @Nullable PersistenceUnitInfo getPersistenceUnitInfo() {
return this.persistenceUnitInfo;
}
@Override
@Nullable
public String getPersistenceUnitName() {
public @Nullable String getPersistenceUnitName() {
if (this.persistenceUnitInfo != null) {
return this.persistenceUnitInfo.getPersistenceUnitName();
}
@@ -441,8 +437,7 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage
}
@Override
@Nullable
public DataSource getDataSource() {
public @Nullable DataSource getDataSource() {
if (this.persistenceUnitInfo != null) {
return (this.persistenceUnitInfo.getJtaDataSource() != null ?
this.persistenceUnitInfo.getJtaDataSource() :

View File

@@ -22,8 +22,7 @@ import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import jakarta.persistence.PersistenceException;
import jakarta.persistence.spi.PersistenceProvider;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* {@link org.springframework.beans.factory.FactoryBean} that creates a JPA
@@ -91,8 +90,7 @@ public class LocalEntityManagerFactoryBean extends AbstractEntityManagerFactoryB
* @see #getJpaPropertyMap()
*/
@Override
@Nullable
public DataSource getDataSource() {
public @Nullable DataSource getDataSource() {
return (DataSource) getJpaPropertyMap().get(DATASOURCE_PROPERTY);
}

View File

@@ -35,8 +35,8 @@ import jakarta.persistence.StoredProcedureQuery;
import jakarta.persistence.TransactionRequiredException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
@@ -190,13 +190,11 @@ public abstract class SharedEntityManagerCreator {
private final EntityManagerFactory targetFactory;
@Nullable
private final Map<?, ?> properties;
private final @Nullable Map<?, ?> properties;
private final boolean synchronizedWithTransaction;
@Nullable
private transient volatile ClassLoader proxyClassLoader;
private transient volatile @Nullable ClassLoader proxyClassLoader;
public SharedEntityManagerInvocationHandler(
EntityManagerFactory target, @Nullable Map<?, ?> properties, boolean synchronizedWithTransaction) {
@@ -217,8 +215,7 @@ public abstract class SharedEntityManagerCreator {
}
@Override
@Nullable
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// Invocation on EntityManager interface coming in...
switch (method.getName()) {
@@ -362,11 +359,9 @@ public abstract class SharedEntityManagerCreator {
private final Query target;
@Nullable
private EntityManager entityManager;
private @Nullable EntityManager entityManager;
@Nullable
private Map<Object, Object> outputParameters;
private @Nullable Map<Object, Object> outputParameters;
public DeferredQueryInvocationHandler(Query target, EntityManager entityManager) {
this.target = target;

View File

@@ -3,9 +3,7 @@
* Contains EntityManagerFactory helper classes, a template plus callback for JPA access,
* and an implementation of Spring's transaction SPI for local JPA transactions.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.orm.jpa;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -22,8 +22,8 @@ import java.security.ProtectionDomain;
import jakarta.persistence.spi.ClassTransformer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -53,8 +53,7 @@ class ClassFileTransformerAdapter implements ClassFileTransformer {
@Override
@Nullable
public byte[] transform(
public byte @Nullable [] transform(
ClassLoader loader, String className, Class<?> classBeingRedefined,
ProtectionDomain protectionDomain, byte[] classfileBuffer) {

View File

@@ -33,6 +33,7 @@ import jakarta.persistence.ValidationMode;
import jakarta.persistence.spi.PersistenceUnitInfo;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ResourceLoaderAware;
@@ -47,7 +48,6 @@ import org.springframework.instrument.classloading.LoadTimeWeaver;
import org.springframework.jdbc.datasource.lookup.DataSourceLookup;
import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup;
import org.springframework.jdbc.datasource.lookup.MapDataSourceLookup;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ResourceUtils;
@@ -104,43 +104,31 @@ public class DefaultPersistenceUnitManager
private String[] persistenceXmlLocations = new String[] {DEFAULT_PERSISTENCE_XML_LOCATION};
@Nullable
private String defaultPersistenceUnitRootLocation = ORIGINAL_DEFAULT_PERSISTENCE_UNIT_ROOT_LOCATION;
private @Nullable String defaultPersistenceUnitRootLocation = ORIGINAL_DEFAULT_PERSISTENCE_UNIT_ROOT_LOCATION;
@Nullable
private String defaultPersistenceUnitName = ORIGINAL_DEFAULT_PERSISTENCE_UNIT_NAME;
private @Nullable String defaultPersistenceUnitName = ORIGINAL_DEFAULT_PERSISTENCE_UNIT_NAME;
@Nullable
private PersistenceManagedTypes managedTypes;
private @Nullable PersistenceManagedTypes managedTypes;
@Nullable
private String[] packagesToScan;
private String @Nullable [] packagesToScan;
@Nullable
private ManagedClassNameFilter managedClassNameFilter;
private @Nullable ManagedClassNameFilter managedClassNameFilter;
@Nullable
private String[] mappingResources;
private String @Nullable [] mappingResources;
@Nullable
private SharedCacheMode sharedCacheMode;
private @Nullable SharedCacheMode sharedCacheMode;
@Nullable
private ValidationMode validationMode;
private @Nullable ValidationMode validationMode;
private DataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
@Nullable
private DataSource defaultDataSource;
private @Nullable DataSource defaultDataSource;
@Nullable
private DataSource defaultJtaDataSource;
private @Nullable DataSource defaultJtaDataSource;
@Nullable
private PersistenceUnitPostProcessor[] persistenceUnitPostProcessors;
private PersistenceUnitPostProcessor @Nullable [] persistenceUnitPostProcessors;
@Nullable
private LoadTimeWeaver loadTimeWeaver;
private @Nullable LoadTimeWeaver loadTimeWeaver;
private ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
@@ -329,8 +317,7 @@ public class DefaultPersistenceUnitManager
* persistence provider, resolving data source names in {@code persistence.xml}
* against Spring-managed DataSource instances.
*/
@Nullable
public DataSourceLookup getDataSourceLookup() {
public @Nullable DataSourceLookup getDataSourceLookup() {
return this.dataSourceLookup;
}
@@ -351,8 +338,7 @@ public class DefaultPersistenceUnitManager
* Return the JDBC DataSource that the JPA persistence provider is supposed to use
* for accessing the database if none has been specified in {@code persistence.xml}.
*/
@Nullable
public DataSource getDefaultDataSource() {
public @Nullable DataSource getDefaultDataSource() {
return this.defaultDataSource;
}
@@ -373,8 +359,7 @@ public class DefaultPersistenceUnitManager
* Return the JTA-aware DataSource that the JPA persistence provider is supposed to use
* for accessing the database if none has been specified in {@code persistence.xml}.
*/
@Nullable
public DataSource getDefaultJtaDataSource() {
public @Nullable DataSource getDefaultJtaDataSource() {
return this.defaultJtaDataSource;
}
@@ -384,7 +369,7 @@ public class DefaultPersistenceUnitManager
* <p>Such post-processors can, for example, register further entity classes and
* jar files, in addition to the metadata read from {@code persistence.xml}.
*/
public void setPersistenceUnitPostProcessors(@Nullable PersistenceUnitPostProcessor... postProcessors) {
public void setPersistenceUnitPostProcessors(PersistenceUnitPostProcessor @Nullable ... postProcessors) {
this.persistenceUnitPostProcessors = postProcessors;
}
@@ -392,8 +377,7 @@ public class DefaultPersistenceUnitManager
* Return the PersistenceUnitPostProcessors to be applied to each
* PersistenceUnitInfo that has been parsed by this manager.
*/
@Nullable
public PersistenceUnitPostProcessor[] getPersistenceUnitPostProcessors() {
public PersistenceUnitPostProcessor @Nullable [] getPersistenceUnitPostProcessors() {
return this.persistenceUnitPostProcessors;
}
@@ -424,8 +408,7 @@ public class DefaultPersistenceUnitManager
* Return the Spring LoadTimeWeaver to use for class instrumentation according
* to the JPA class transformer contract.
*/
@Nullable
public LoadTimeWeaver getLoadTimeWeaver() {
public @Nullable LoadTimeWeaver getLoadTimeWeaver() {
return this.loadTimeWeaver;
}
@@ -594,8 +577,7 @@ public class DefaultPersistenceUnitManager
* @return the persistence unit root URL to pass to the JPA PersistenceProvider
* @see #setDefaultPersistenceUnitRootLocation
*/
@Nullable
private URL determineDefaultPersistenceUnitRootUrl() {
private @Nullable URL determineDefaultPersistenceUnitRootUrl() {
if (this.defaultPersistenceUnitRootLocation == null) {
return null;
}
@@ -618,8 +600,7 @@ public class DefaultPersistenceUnitManager
* <p>Checks whether a "META-INF/orm.xml" file exists in the classpath and uses it
* if it is not co-located with a "META-INF/persistence.xml" file.
*/
@Nullable
private Resource getOrmXmlForDefaultPersistenceUnit() {
private @Nullable Resource getOrmXmlForDefaultPersistenceUnit() {
Resource ormXml = this.resourcePatternResolver.getResource(
this.defaultPersistenceUnitRootLocation + DEFAULT_ORM_XML_RESOURCE);
if (ormXml.exists()) {
@@ -647,8 +628,7 @@ public class DefaultPersistenceUnitManager
* @param persistenceUnitName the name of the desired persistence unit
* @return the PersistenceUnitInfo in mutable form, or {@code null} if not available
*/
@Nullable
protected final MutablePersistenceUnitInfo getPersistenceUnitInfo(String persistenceUnitName) {
protected final @Nullable MutablePersistenceUnitInfo getPersistenceUnitInfo(String persistenceUnitName) {
PersistenceUnitInfo pui = this.persistenceUnitInfos.get(persistenceUnitName);
return (MutablePersistenceUnitInfo) pui;
}

View File

@@ -27,8 +27,8 @@ import jakarta.persistence.SharedCacheMode;
import jakarta.persistence.ValidationMode;
import jakarta.persistence.spi.ClassTransformer;
import jakarta.persistence.spi.PersistenceUnitTransactionType;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -48,27 +48,21 @@ import org.springframework.util.ClassUtils;
@SuppressWarnings("removal")
public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
@Nullable
private String persistenceUnitName;
private @Nullable String persistenceUnitName;
@Nullable
private String persistenceProviderClassName;
private @Nullable String persistenceProviderClassName;
@Nullable
private PersistenceUnitTransactionType transactionType;
private @Nullable PersistenceUnitTransactionType transactionType;
@Nullable
private DataSource nonJtaDataSource;
private @Nullable DataSource nonJtaDataSource;
@Nullable
private DataSource jtaDataSource;
private @Nullable DataSource jtaDataSource;
private final List<String> mappingFileNames = new ArrayList<>();
private final List<URL> jarFileUrls = new ArrayList<>();
@Nullable
private URL persistenceUnitRootUrl;
private @Nullable URL persistenceUnitRootUrl;
private final List<String> managedClassNames = new ArrayList<>();
@@ -84,8 +78,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
private String persistenceXMLSchemaVersion = "2.0";
@Nullable
private String persistenceProviderPackageName;
private @Nullable String persistenceProviderPackageName;
public void setPersistenceUnitName(@Nullable String persistenceUnitName) {
@@ -93,8 +86,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
}
@Override
@Nullable
public String getPersistenceUnitName() {
public @Nullable String getPersistenceUnitName() {
return this.persistenceUnitName;
}
@@ -103,8 +95,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
}
@Override
@Nullable
public String getPersistenceProviderClassName() {
public @Nullable String getPersistenceProviderClassName() {
return this.persistenceProviderClassName;
}
@@ -128,8 +119,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
}
@Override
@Nullable
public DataSource getJtaDataSource() {
public @Nullable DataSource getJtaDataSource() {
return this.jtaDataSource;
}
@@ -138,8 +128,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
}
@Override
@Nullable
public DataSource getNonJtaDataSource() {
public @Nullable DataSource getNonJtaDataSource() {
return this.nonJtaDataSource;
}
@@ -166,8 +155,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
}
@Override
@Nullable
public URL getPersistenceUnitRootUrl() {
public @Nullable URL getPersistenceUnitRootUrl() {
return this.persistenceUnitRootUrl;
}
@@ -258,8 +246,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
this.persistenceProviderPackageName = persistenceProviderPackageName;
}
@Nullable
public String getPersistenceProviderPackageName() {
public @Nullable String getPersistenceProviderPackageName() {
return this.persistenceProviderPackageName;
}
@@ -269,8 +256,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
* @see org.springframework.util.ClassUtils#getDefaultClassLoader()
*/
@Override
@Nullable
public ClassLoader getClassLoader() {
public @Nullable ClassLoader getClassLoader() {
return ClassUtils.getDefaultClassLoader();
}
@@ -291,14 +277,12 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo {
}
@Override
@Nullable
public String getScopeAnnotationName() {
public @Nullable String getScopeAnnotationName() {
return null;
}
@Override
@Nullable
public List<String> getQualifierAnnotationNames() {
public @Nullable List<String> getQualifierAnnotationNames() {
return null;
}

View File

@@ -20,8 +20,8 @@ import java.net.URL;
import java.util.List;
import jakarta.persistence.spi.PersistenceUnitInfo;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -54,8 +54,7 @@ public interface PersistenceManagedTypes {
* @return the persistence unit root url
* @see PersistenceUnitInfo#getPersistenceUnitRootUrl()
*/
@Nullable
URL getPersistenceUnitRootUrl();
@Nullable URL getPersistenceUnitRootUrl();
/**
* Create an instance using the specified managed class names.

View File

@@ -33,6 +33,7 @@ import jakarta.persistence.PostUpdate;
import jakarta.persistence.PrePersist;
import jakarta.persistence.PreRemove;
import jakarta.persistence.PreUpdate;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.GeneratedMethod;
import org.springframework.aot.generate.GenerationContext;
@@ -50,7 +51,6 @@ import org.springframework.beans.factory.support.RegisteredBean;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.javapoet.CodeBlock;
import org.springframework.javapoet.ParameterizedTypeName;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
@@ -71,9 +71,8 @@ class PersistenceManagedTypesBeanRegistrationAotProcessor implements BeanRegistr
private static final boolean jpaPresent = ClassUtils.isPresent("jakarta.persistence.Entity",
PersistenceManagedTypesBeanRegistrationAotProcessor.class.getClassLoader());
@Nullable
@Override
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
if (jpaPresent) {
if (PersistenceManagedTypes.class.isAssignableFrom(registeredBean.getBeanClass())) {
return BeanRegistrationAotContribution.withCustomCodeFragments(codeFragments ->
@@ -230,8 +229,7 @@ class PersistenceManagedTypesBeanRegistrationAotProcessor implements BeanRegistr
}
}
@Nullable
private static Class<? extends Annotation> loadClass(String className, @Nullable ClassLoader classLoader) {
private static @Nullable Class<? extends Annotation> loadClass(String className, @Nullable ClassLoader classLoader) {
try {
return (Class<? extends Annotation>) ClassUtils.forName(className, classLoader);
}

View File

@@ -29,6 +29,7 @@ import jakarta.persistence.Embeddable;
import jakarta.persistence.Entity;
import jakarta.persistence.MappedSuperclass;
import jakarta.persistence.PersistenceException;
import org.jspecify.annotations.Nullable;
import org.springframework.context.index.CandidateComponentsIndex;
import org.springframework.context.index.CandidateComponentsIndexLoader;
@@ -43,7 +44,6 @@ import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.AnnotationTypeFilter;
import org.springframework.core.type.filter.TypeFilter;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ResourceUtils;
@@ -77,8 +77,7 @@ public final class PersistenceManagedTypesScanner {
private final ResourcePatternResolver resourcePatternResolver;
@Nullable
private final CandidateComponentsIndex componentsIndex;
private final @Nullable CandidateComponentsIndex componentsIndex;
private final ManagedClassNameFilter managedClassNameFilter;
@@ -192,8 +191,7 @@ public final class PersistenceManagedTypesScanner {
private final List<String> managedPackages = new ArrayList<>();
@Nullable
private URL persistenceUnitRootUrl;
private @Nullable URL persistenceUnitRootUrl;
PersistenceManagedTypes toJpaManagedTypes() {
return new SimplePersistenceManagedTypes(this.managedClassNames,

View File

@@ -31,6 +31,7 @@ import jakarta.persistence.ValidationMode;
import jakarta.persistence.spi.PersistenceUnitTransactionType;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.ErrorHandler;
@@ -39,7 +40,6 @@ import org.xml.sax.SAXException;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.jdbc.datasource.lookup.DataSourceLookup;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
@@ -331,8 +331,7 @@ final class PersistenceUnitReader {
* @return the corresponding persistence unit root URL
* @throws IOException if the checking failed
*/
@Nullable
static URL determinePersistenceUnitRootUrl(Resource resource) throws IOException {
static @Nullable URL determinePersistenceUnitRootUrl(Resource resource) throws IOException {
URL originalURL = resource.getURL();
// If we get an archive, simply return the jar URL (section 6.2 from the JPA spec)

View File

@@ -19,7 +19,7 @@ package org.springframework.orm.jpa.persistenceunit;
import java.net.URL;
import java.util.List;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* A simple {@link PersistenceManagedTypes} implementation that holds the list
@@ -34,8 +34,7 @@ class SimplePersistenceManagedTypes implements PersistenceManagedTypes {
private final List<String> managedPackages;
@Nullable
private final URL persistenceUnitRootUrl;
private final @Nullable URL persistenceUnitRootUrl;
SimplePersistenceManagedTypes(List<String> managedClassNames, List<String> managedPackages,
@@ -60,8 +59,7 @@ class SimplePersistenceManagedTypes implements PersistenceManagedTypes {
}
@Override
@Nullable
public URL getPersistenceUnitRootUrl() {
public @Nullable URL getPersistenceUnitRootUrl() {
return this.persistenceUnitRootUrl;
}

View File

@@ -18,11 +18,11 @@ package org.springframework.orm.jpa.persistenceunit;
import jakarta.persistence.spi.ClassTransformer;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.core.DecoratingClassLoader;
import org.springframework.instrument.classloading.LoadTimeWeaver;
import org.springframework.instrument.classloading.SimpleThrowawayClassLoader;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -39,11 +39,9 @@ import org.springframework.util.Assert;
*/
class SpringPersistenceUnitInfo extends MutablePersistenceUnitInfo {
@Nullable
private LoadTimeWeaver loadTimeWeaver;
private @Nullable LoadTimeWeaver loadTimeWeaver;
@Nullable
private ClassLoader classLoader;
private @Nullable ClassLoader classLoader;
/**
@@ -70,8 +68,7 @@ class SpringPersistenceUnitInfo extends MutablePersistenceUnitInfo {
* if specified.
*/
@Override
@Nullable
public ClassLoader getClassLoader() {
public @Nullable ClassLoader getClassLoader() {
return this.classLoader;
}

View File

@@ -1,9 +1,7 @@
/**
* Internal support for managing JPA persistence units.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.orm.jpa.persistenceunit;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -21,8 +21,8 @@ import java.util.concurrent.Callable;
import jakarta.persistence.EntityManagerFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.EntityManagerFactoryUtils;
import org.springframework.orm.jpa.EntityManagerHolder;
import org.springframework.transaction.support.TransactionSynchronizationManager;

View File

@@ -25,9 +25,9 @@ import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.EntityManagerFactoryUtils;
import org.springframework.orm.jpa.EntityManagerHolder;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -75,14 +75,11 @@ public class OpenEntityManagerInViewFilter extends OncePerRequestFilter {
public static final String DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME = "entityManagerFactory";
@Nullable
private String entityManagerFactoryBeanName;
private @Nullable String entityManagerFactoryBeanName;
@Nullable
private String persistenceUnitName;
private @Nullable String persistenceUnitName;
@Nullable
private volatile EntityManagerFactory entityManagerFactory;
private volatile @Nullable EntityManagerFactory entityManagerFactory;
/**
@@ -101,8 +98,7 @@ public class OpenEntityManagerInViewFilter extends OncePerRequestFilter {
* Return the bean name of the EntityManagerFactory to fetch from Spring's
* root application context.
*/
@Nullable
protected String getEntityManagerFactoryBeanName() {
protected @Nullable String getEntityManagerFactoryBeanName() {
return this.entityManagerFactoryBeanName;
}
@@ -123,8 +119,7 @@ public class OpenEntityManagerInViewFilter extends OncePerRequestFilter {
/**
* Return the name of the persistence unit to access the EntityManagerFactory for, if any.
*/
@Nullable
protected String getPersistenceUnitName() {
protected @Nullable String getPersistenceUnitName() {
return this.persistenceUnitName;
}

View File

@@ -19,10 +19,10 @@ package org.springframework.orm.jpa.support;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.PersistenceException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.EntityManagerFactoryAccessor;
import org.springframework.orm.jpa.EntityManagerFactoryUtils;
import org.springframework.orm.jpa.EntityManagerHolder;

View File

@@ -38,6 +38,7 @@ import jakarta.persistence.PersistenceContextType;
import jakarta.persistence.PersistenceProperty;
import jakarta.persistence.PersistenceUnit;
import jakarta.persistence.SynchronizationType;
import org.jspecify.annotations.Nullable;
import org.springframework.aot.generate.GeneratedClass;
import org.springframework.aot.generate.GeneratedMethod;
@@ -73,7 +74,6 @@ import org.springframework.javapoet.CodeBlock;
import org.springframework.javapoet.MethodSpec;
import org.springframework.jndi.JndiLocatorDelegate;
import org.springframework.jndi.JndiTemplate;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.EntityManagerFactoryInfo;
import org.springframework.orm.jpa.EntityManagerFactoryUtils;
import org.springframework.orm.jpa.EntityManagerProxy;
@@ -191,26 +191,21 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
DestructionAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor, BeanRegistrationAotProcessor,
PriorityOrdered, BeanFactoryAware, Serializable {
@Nullable
private Object jndiEnvironment;
private @Nullable Object jndiEnvironment;
private boolean resourceRef = true;
@Nullable
private transient Map<String, String> persistenceUnits;
private transient @Nullable Map<String, String> persistenceUnits;
@Nullable
private transient Map<String, String> persistenceContexts;
private transient @Nullable Map<String, String> persistenceContexts;
@Nullable
private transient Map<String, String> extendedPersistenceContexts;
private transient @Nullable Map<String, String> extendedPersistenceContexts;
private transient String defaultPersistenceUnitName = "";
private int order = Ordered.LOWEST_PRECEDENCE - 4;
@Nullable
private transient ListableBeanFactory beanFactory;
private transient @Nullable ListableBeanFactory beanFactory;
private final transient Map<String, InjectionMetadata> injectionMetadataCache = new ConcurrentHashMap<>(256);
@@ -359,8 +354,7 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
}
@Override
@Nullable
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
Class<?> beanClass = registeredBean.getBeanClass();
String beanName = registeredBean.getBeanName();
RootBeanDefinition beanDefinition = registeredBean.getMergedBeanDefinition();
@@ -479,8 +473,7 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
* or {@code null} if none found
* @see #setPersistenceUnits
*/
@Nullable
protected EntityManagerFactory getPersistenceUnit(@Nullable String unitName) {
protected @Nullable EntityManagerFactory getPersistenceUnit(@Nullable String unitName) {
if (this.persistenceUnits != null) {
String unitNameForLookup = (unitName != null ? unitName : "");
if (unitNameForLookup.isEmpty()) {
@@ -511,8 +504,7 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
* @see #setPersistenceContexts
* @see #setExtendedPersistenceContexts
*/
@Nullable
protected EntityManager getPersistenceContext(@Nullable String unitName, boolean extended) {
protected @Nullable EntityManager getPersistenceContext(@Nullable String unitName, boolean extended) {
Map<String, String> contexts = (extended ? this.extendedPersistenceContexts : this.persistenceContexts);
if (contexts != null) {
String unitNameForLookup = (unitName != null ? unitName : "");
@@ -648,13 +640,11 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar
private final String unitName;
@Nullable
private PersistenceContextType type;
private @Nullable PersistenceContextType type;
private boolean synchronizedWithTransaction = false;
@Nullable
private Properties properties;
private @Nullable Properties properties;
public PersistenceElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) {
super(member, pd);

View File

@@ -18,10 +18,10 @@ package org.springframework.orm.jpa.support;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.EntityManagerFactoryAccessor;
import org.springframework.orm.jpa.EntityManagerFactoryInfo;
import org.springframework.orm.jpa.SharedEntityManagerCreator;
@@ -52,13 +52,11 @@ import org.springframework.util.Assert;
public class SharedEntityManagerBean extends EntityManagerFactoryAccessor
implements FactoryBean<EntityManager>, InitializingBean {
@Nullable
private Class<? extends EntityManager> entityManagerInterface;
private @Nullable Class<? extends EntityManager> entityManagerInterface;
private boolean synchronizedWithTransaction = true;
@Nullable
private EntityManager shared;
private @Nullable EntityManager shared;
/**
@@ -108,8 +106,7 @@ public class SharedEntityManagerBean extends EntityManagerFactoryAccessor
@Override
@Nullable
public EntityManager getObject() {
public @Nullable EntityManager getObject() {
return this.shared;
}

View File

@@ -1,9 +1,7 @@
/**
* Classes supporting the {@code org.springframework.orm.jpa} package.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.orm.jpa.support;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -22,8 +22,8 @@ import java.util.Map;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.spi.PersistenceUnitInfo;
import org.jspecify.annotations.Nullable;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.JpaDialect;
import org.springframework.orm.jpa.JpaVendorAdapter;
@@ -39,8 +39,7 @@ public abstract class AbstractJpaVendorAdapter implements JpaVendorAdapter {
private Database database = Database.DEFAULT;
@Nullable
private String databasePlatform;
private @Nullable String databasePlatform;
private boolean generateDdl = false;
@@ -77,8 +76,7 @@ public abstract class AbstractJpaVendorAdapter implements JpaVendorAdapter {
/**
* Return the name of the target database to operate on.
*/
@Nullable
protected String getDatabasePlatform() {
protected @Nullable String getDatabasePlatform() {
return this.databasePlatform;
}
@@ -125,8 +123,7 @@ public abstract class AbstractJpaVendorAdapter implements JpaVendorAdapter {
@Override
@Nullable
public String getPersistenceProviderRootPackage() {
public @Nullable String getPersistenceProviderRootPackage() {
return null;
}
@@ -141,8 +138,7 @@ public abstract class AbstractJpaVendorAdapter implements JpaVendorAdapter {
}
@Override
@Nullable
public JpaDialect getJpaDialect() {
public @Nullable JpaDialect getJpaDialect() {
return null;
}

View File

@@ -25,9 +25,9 @@ import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceException;
import org.eclipse.persistence.sessions.DatabaseLogin;
import org.eclipse.persistence.sessions.UnitOfWork;
import org.jspecify.annotations.Nullable;
import org.springframework.jdbc.datasource.ConnectionHandle;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.DefaultJpaDialect;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionException;
@@ -96,8 +96,7 @@ public class EclipseLinkJpaDialect extends DefaultJpaDialect {
@Override
@Nullable
public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
public @Nullable Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
throws PersistenceException, SQLException, TransactionException {
int currentIsolationLevel = definition.getIsolationLevel();
@@ -172,8 +171,7 @@ public class EclipseLinkJpaDialect extends DefaultJpaDialect {
private final EntityManager entityManager;
@Nullable
private Connection connection;
private @Nullable Connection connection;
public EclipseLinkConnectionHandle(EntityManager entityManager) {
this.entityManager = entityManager;

View File

@@ -25,8 +25,7 @@ import jakarta.persistence.spi.PersistenceProvider;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.eclipse.persistence.config.TargetDatabase;
import org.eclipse.persistence.jpa.JpaEntityManager;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Eclipse
@@ -91,8 +90,7 @@ public class EclipseLinkJpaVendorAdapter extends AbstractJpaVendorAdapter {
* @param database the specified database
* @return the EclipseLink target database name, or {@code null} if none found
*/
@Nullable
protected String determineTargetDatabaseName(Database database) {
protected @Nullable String determineTargetDatabaseName(Database database) {
return switch (database) {
case DB2 -> TargetDatabase.DB2;
case DERBY -> TargetDatabase.Derby;

View File

@@ -47,6 +47,7 @@ import org.hibernate.exception.DataException;
import org.hibernate.exception.JDBCConnectionException;
import org.hibernate.exception.LockAcquisitionException;
import org.hibernate.exception.SQLGrammarException;
import org.jspecify.annotations.Nullable;
import org.springframework.dao.CannotAcquireLockException;
import org.springframework.dao.DataAccessException;
@@ -61,7 +62,6 @@ import org.springframework.jdbc.datasource.ConnectionHandle;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.jdbc.support.SQLExceptionSubclassTranslator;
import org.springframework.jdbc.support.SQLExceptionTranslator;
import org.springframework.lang.Nullable;
import org.springframework.orm.ObjectOptimisticLockingFailureException;
import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.orm.jpa.DefaultJpaDialect;
@@ -89,11 +89,9 @@ public class HibernateJpaDialect extends DefaultJpaDialect {
boolean prepareConnection = true;
@Nullable
private SQLExceptionTranslator jdbcExceptionTranslator;
private @Nullable SQLExceptionTranslator jdbcExceptionTranslator;
@Nullable
private SQLExceptionTranslator transactionExceptionTranslator = new SQLExceptionSubclassTranslator();
private @Nullable SQLExceptionTranslator transactionExceptionTranslator = new SQLExceptionSubclassTranslator();
/**
@@ -198,8 +196,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect {
return new SessionTransactionData(session, previousFlushMode, false, null, readOnly);
}
@Nullable
protected FlushMode prepareFlushMode(Session session, boolean readOnly) throws PersistenceException {
protected @Nullable FlushMode prepareFlushMode(Session session, boolean readOnly) throws PersistenceException {
FlushMode flushMode = session.getHibernateFlushMode();
if (readOnly) {
// We should suppress flushing for a read-only transaction.
@@ -235,8 +232,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect {
}
@Override
@Nullable
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
public @Nullable DataAccessException translateExceptionIfPossible(RuntimeException ex) {
if (ex instanceof HibernateException hibernateEx) {
return convertHibernateAccessException(hibernateEx);
}
@@ -345,8 +341,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect {
return entityManager.unwrap(SessionImplementor.class);
}
@Nullable
protected Object getIdentifier(HibernateException hibEx) {
protected @Nullable Object getIdentifier(HibernateException hibEx) {
try {
// getIdentifier declares Serializable return value on 5.x but Object on 6.x
// -> not binary compatible, let's invoke it reflectively for the time being
@@ -362,13 +357,11 @@ public class HibernateJpaDialect extends DefaultJpaDialect {
private final SessionImplementor session;
@Nullable
private final FlushMode previousFlushMode;
private final @Nullable FlushMode previousFlushMode;
private final boolean needsConnectionReset;
@Nullable
private final Integer previousIsolationLevel;
private final @Nullable Integer previousIsolationLevel;
private final boolean readOnly;

View File

@@ -37,8 +37,7 @@ import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.dialect.SybaseDialect;
import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Hibernate.
@@ -177,8 +176,7 @@ public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter {
* @return the Hibernate database dialect class, or {@code null} if none found
* @see #determineDatabaseDialectName
*/
@Nullable
protected Class<?> determineDatabaseDialectClass(Database database) {
protected @Nullable Class<?> determineDatabaseDialectClass(Database database) {
return switch (database) {
case DB2 -> DB2Dialect.class;
case H2 -> H2Dialect.class;
@@ -201,8 +199,7 @@ public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter {
* @since 7.0
* @see #determineDatabaseDialectClass
*/
@Nullable
protected String determineDatabaseDialectName(Database database) {
protected @Nullable String determineDatabaseDialectName(Database database) {
return switch (database) {
case DERBY -> "org.hibernate.community.dialect.DerbyDialect";
default -> null;

View File

@@ -1,9 +1,7 @@
/**
* Support classes for adapting to specific JPA vendors.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.orm.jpa.vendor;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -2,9 +2,7 @@
* Root package for Spring's O/R Mapping integration classes.
* Contains generic DataAccessExceptions related to O/R Mapping.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.orm;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;

View File

@@ -29,6 +29,7 @@ import jakarta.persistence.PersistenceContext;
import jakarta.persistence.PersistenceProperty;
import jakarta.persistence.PersistenceUnit;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -43,7 +44,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.core.test.tools.CompileWithForkedClassLoader;
import org.springframework.core.test.tools.Compiled;
import org.springframework.core.test.tools.TestCompiler;
import org.springframework.lang.Nullable;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
@@ -215,8 +215,7 @@ class PersistenceAnnotationBeanPostProcessorAotContributionTests {
.compile(compiled -> result.accept(new Invoker(compiled), compiled));
}
@Nullable
private BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
private @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
PersistenceAnnotationBeanPostProcessor postProcessor = new PersistenceAnnotationBeanPostProcessor();
return postProcessor.processAheadOfTime(registeredBean);
}

View File

@@ -22,11 +22,11 @@ import jakarta.persistence.EntityTransaction;
import jakarta.persistence.PersistenceContext;
import jakarta.persistence.PersistenceContextType;
import jakarta.persistence.SynchronizationType;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.support.TransactionSynchronizationManager;

View File

@@ -31,6 +31,7 @@ import jakarta.persistence.PersistenceContextType;
import jakarta.persistence.PersistenceProperty;
import jakarta.persistence.PersistenceUnit;
import org.hibernate.Session;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.FactoryBean;
@@ -40,7 +41,6 @@ import org.springframework.context.support.GenericApplicationContext;
import org.springframework.context.testfixture.SimpleMapScope;
import org.springframework.context.testfixture.jndi.ExpectedLookupTemplate;
import org.springframework.core.testfixture.io.SerializationTestUtils;
import org.springframework.lang.Nullable;
import org.springframework.orm.jpa.AbstractEntityManagerFactoryBeanTests;
import org.springframework.orm.jpa.DefaultJpaDialect;
import org.springframework.orm.jpa.EntityManagerFactoryInfo;