diff --git a/config/checkstyle/checkstyle-suppressions.xml b/config/checkstyle/checkstyle-suppressions.xml
index d869769c17a..66d71260f6a 100644
--- a/config/checkstyle/checkstyle-suppressions.xml
+++ b/config/checkstyle/checkstyle-suppressions.xml
@@ -91,4 +91,5 @@
+
diff --git a/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/EntityManagerFactoryBuilder.java b/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/EntityManagerFactoryBuilder.java
index 1cffb77e427..9f32da75362 100644
--- a/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/EntityManagerFactoryBuilder.java
+++ b/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/EntityManagerFactoryBuilder.java
@@ -26,6 +26,8 @@ import java.util.function.Function;
import javax.sql.DataSource;
+import org.jspecify.annotations.Nullable;
+
import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
@@ -53,15 +55,15 @@ public class EntityManagerFactoryBuilder {
private final JpaVendorAdapter jpaVendorAdapter;
- private final PersistenceUnitManager persistenceUnitManager;
+ private final @Nullable PersistenceUnitManager persistenceUnitManager;
private final Function> jpaPropertiesFactory;
- private final URL persistenceUnitRootLocation;
+ private final @Nullable URL persistenceUnitRootLocation;
- private AsyncTaskExecutor bootstrapExecutor;
+ private @Nullable AsyncTaskExecutor bootstrapExecutor;
- private PersistenceUnitPostProcessor[] persistenceUnitPostProcessors;
+ private PersistenceUnitPostProcessor @Nullable [] persistenceUnitPostProcessors;
/**
* Create a new instance passing in the common pieces that will be shared if multiple
@@ -74,7 +76,8 @@ public class EntityManagerFactoryBuilder {
* @since 3.4.4
*/
public EntityManagerFactoryBuilder(JpaVendorAdapter jpaVendorAdapter,
- Function> jpaPropertiesFactory, PersistenceUnitManager persistenceUnitManager) {
+ Function> jpaPropertiesFactory,
+ @Nullable PersistenceUnitManager persistenceUnitManager) {
this(jpaVendorAdapter, jpaPropertiesFactory, persistenceUnitManager, null);
}
@@ -91,8 +94,8 @@ public class EntityManagerFactoryBuilder {
* @since 3.4.4
*/
public EntityManagerFactoryBuilder(JpaVendorAdapter jpaVendorAdapter,
- Function> jpaPropertiesFactory, PersistenceUnitManager persistenceUnitManager,
- URL persistenceUnitRootLocation) {
+ Function> jpaPropertiesFactory,
+ @Nullable PersistenceUnitManager persistenceUnitManager, @Nullable URL persistenceUnitRootLocation) {
this.jpaVendorAdapter = jpaVendorAdapter;
this.persistenceUnitManager = persistenceUnitManager;
this.jpaPropertiesFactory = jpaPropertiesFactory;
@@ -137,15 +140,15 @@ public class EntityManagerFactoryBuilder {
private final DataSource dataSource;
- private PersistenceManagedTypes managedTypes;
+ private @Nullable PersistenceManagedTypes managedTypes;
- private String[] packagesToScan;
+ private String @Nullable [] packagesToScan;
- private String persistenceUnit;
+ private @Nullable String persistenceUnit;
private final Map properties = new HashMap<>();
- private String[] mappingResources;
+ private String @Nullable [] mappingResources;
private boolean jta;
@@ -159,7 +162,7 @@ public class EntityManagerFactoryBuilder {
* @param managedTypes managed types.
* @return the builder for fluent usage
*/
- public Builder managedTypes(PersistenceManagedTypes managedTypes) {
+ public Builder managedTypes(@Nullable PersistenceManagedTypes managedTypes) {
this.managedTypes = managedTypes;
return this;
}
@@ -170,7 +173,7 @@ public class EntityManagerFactoryBuilder {
* @return the builder for fluent usage
* @see #managedTypes(PersistenceManagedTypes)
*/
- public Builder packages(String... packagesToScan) {
+ public Builder packages(String @Nullable ... packagesToScan) {
this.packagesToScan = packagesToScan;
return this;
}
@@ -197,7 +200,7 @@ public class EntityManagerFactoryBuilder {
* @param persistenceUnit the name of the persistence unit
* @return the builder for fluent usage
*/
- public Builder persistenceUnit(String persistenceUnit) {
+ public Builder persistenceUnit(@Nullable String persistenceUnit) {
this.persistenceUnit = persistenceUnit;
return this;
}
@@ -223,7 +226,7 @@ public class EntityManagerFactoryBuilder {
* @param mappingResources the mapping resources to use
* @return the builder for fluent usage
*/
- public Builder mappingResources(String... mappingResources) {
+ public Builder mappingResources(String @Nullable ... mappingResources) {
this.mappingResources = mappingResources;
return this;
}
@@ -264,7 +267,7 @@ public class EntityManagerFactoryBuilder {
entityManagerFactoryBean.setManagedTypes(this.managedTypes);
}
else {
- entityManagerFactoryBean.setPackagesToScan(this.packagesToScan);
+ setPackagesToScan(entityManagerFactoryBean);
}
Map jpaProperties = EntityManagerFactoryBuilder.this.jpaPropertiesFactory.apply(this.dataSource);
entityManagerFactoryBean.getJpaPropertyMap().putAll(new LinkedHashMap<>(jpaProperties));
@@ -286,6 +289,14 @@ public class EntityManagerFactoryBuilder {
return entityManagerFactoryBean;
}
+ // TODO: Review this. The test
+ // HibernateJpaAutoConfigurationTests.usesManuallyDefinedLocalContainerEntityManagerFactoryBeanUsingBuilder
+ // fails if an non-null assert is added
+ @SuppressWarnings("NullAway")
+ private void setPackagesToScan(LocalContainerEntityManagerFactoryBean entityManagerFactoryBean) {
+ entityManagerFactoryBean.setPackagesToScan(this.packagesToScan);
+ }
+
}
}
diff --git a/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/autoconfigure/JpaBaseConfiguration.java b/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/autoconfigure/JpaBaseConfiguration.java
index 428c2f1f958..de2cbe802bf 100644
--- a/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/autoconfigure/JpaBaseConfiguration.java
+++ b/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/autoconfigure/JpaBaseConfiguration.java
@@ -25,6 +25,7 @@ import javax.sql.DataSource;
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.factory.BeanFactory;
import org.springframework.beans.factory.ObjectProvider;
@@ -82,7 +83,7 @@ public abstract class JpaBaseConfiguration {
private final JpaProperties properties;
- private final JtaTransactionManager jtaTransactionManager;
+ private final @Nullable JtaTransactionManager jtaTransactionManager;
protected JpaBaseConfiguration(DataSource dataSource, JpaProperties properties,
ObjectProvider jtaTransactionManager) {
@@ -163,7 +164,7 @@ public abstract class JpaBaseConfiguration {
protected void customizeVendorProperties(Map vendorProperties) {
}
- private String[] getMappingResources() {
+ private String @Nullable [] getMappingResources() {
List mappingResources = this.properties.getMappingResources();
return (!ObjectUtils.isEmpty(mappingResources) ? StringUtils.toStringArray(mappingResources) : null);
}
@@ -172,7 +173,7 @@ public abstract class JpaBaseConfiguration {
* Return the JTA transaction manager.
* @return the transaction manager or {@code null}
*/
- protected JtaTransactionManager getJtaTransactionManager() {
+ protected @Nullable JtaTransactionManager getJtaTransactionManager() {
return this.jtaTransactionManager;
}
diff --git a/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/autoconfigure/JpaProperties.java b/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/autoconfigure/JpaProperties.java
index 77bb0d5737e..4d9f151e666 100644
--- a/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/autoconfigure/JpaProperties.java
+++ b/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/autoconfigure/JpaProperties.java
@@ -21,6 +21,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.jspecify.annotations.Nullable;
+
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.orm.jpa.vendor.Database;
@@ -51,13 +53,13 @@ public class JpaProperties {
* Name of the target database to operate on, auto-detected by default. Can be
* alternatively set using the "Database" enum.
*/
- private String databasePlatform;
+ private @Nullable String databasePlatform;
/**
* Target database to operate on, auto-detected by default. Can be alternatively set
* using the "databasePlatform" property.
*/
- private Database database;
+ private @Nullable Database database;
/**
* Whether to initialize the schema on startup.
@@ -73,7 +75,7 @@ public class JpaProperties {
* Register OpenEntityManagerInViewInterceptor. Binds a JPA EntityManager to the
* thread for the entire processing of the request.
*/
- private Boolean openInView;
+ private @Nullable Boolean openInView;
public Map getProperties() {
return this.properties;
@@ -87,19 +89,19 @@ public class JpaProperties {
return this.mappingResources;
}
- public String getDatabasePlatform() {
+ public @Nullable String getDatabasePlatform() {
return this.databasePlatform;
}
- public void setDatabasePlatform(String databasePlatform) {
+ public void setDatabasePlatform(@Nullable String databasePlatform) {
this.databasePlatform = databasePlatform;
}
- public Database getDatabase() {
+ public @Nullable Database getDatabase() {
return this.database;
}
- public void setDatabase(Database database) {
+ public void setDatabase(@Nullable Database database) {
this.database = database;
}
@@ -119,11 +121,11 @@ public class JpaProperties {
this.showSql = showSql;
}
- public Boolean getOpenInView() {
+ public @Nullable Boolean getOpenInView() {
return this.openInView;
}
- public void setOpenInView(Boolean openInView) {
+ public void setOpenInView(@Nullable Boolean openInView) {
this.openInView = openInView;
}
diff --git a/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/autoconfigure/package-info.java b/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/autoconfigure/package-info.java
index f336351258d..b999cec18c8 100644
--- a/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/autoconfigure/package-info.java
+++ b/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/autoconfigure/package-info.java
@@ -17,4 +17,7 @@
/**
* Base Auto-configuration for JPA and Spring ORM.
*/
+@NullMarked
package org.springframework.boot.jpa.autoconfigure;
+
+import org.jspecify.annotations.NullMarked;
diff --git a/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/package-info.java b/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/package-info.java
index eb455d693a8..325ebaff4d8 100644
--- a/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/package-info.java
+++ b/module/spring-boot-jpa/src/main/java/org/springframework/boot/jpa/package-info.java
@@ -17,4 +17,7 @@
/**
* JPA Support classes.
*/
+@NullMarked
package org.springframework.boot.jpa;
+
+import org.jspecify.annotations.NullMarked;