From b8f74b1a1174954a1f28c929904a3328b7e2edde Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Wed, 30 Jul 2025 14:14:32 +0200 Subject: [PATCH] Add nullability annotations to module/spring-boot-data-rest See gh-46587 --- .../RepositoryRestProperties.java | 62 ++++++++++--------- .../SpringBootRepositoryRestConfigurer.java | 5 +- .../data/rest/autoconfigure/package-info.java | 3 + 3 files changed, 38 insertions(+), 32 deletions(-) diff --git a/module/spring-boot-data-rest/src/main/java/org/springframework/boot/data/rest/autoconfigure/RepositoryRestProperties.java b/module/spring-boot-data-rest/src/main/java/org/springframework/boot/data/rest/autoconfigure/RepositoryRestProperties.java index 40906f250cd..394059393ed 100644 --- a/module/spring-boot-data-rest/src/main/java/org/springframework/boot/data/rest/autoconfigure/RepositoryRestProperties.java +++ b/module/spring-boot-data-rest/src/main/java/org/springframework/boot/data/rest/autoconfigure/RepositoryRestProperties.java @@ -16,6 +16,8 @@ package org.springframework.boot.data.rest.autoconfigure; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.data.rest.core.config.RepositoryRestConfiguration; @@ -34,34 +36,34 @@ public class RepositoryRestProperties { /** * Base path to be used by Spring Data REST to expose repository resources. */ - private String basePath; + private @Nullable String basePath; /** * Default size of pages. */ - private Integer defaultPageSize; + private @Nullable Integer defaultPageSize; /** * Maximum size of pages. */ - private Integer maxPageSize; + private @Nullable Integer maxPageSize; /** * Name of the URL query string parameter that indicates what page to return. */ - private String pageParamName; + private @Nullable String pageParamName; /** * Name of the URL query string parameter that indicates how many results to return at * once. */ - private String limitParamName; + private @Nullable String limitParamName; /** * Name of the URL query string parameter that indicates what direction to sort * results. */ - private String sortParamName; + private @Nullable String sortParamName; /** * Strategy to use to determine which repositories get exposed. @@ -71,69 +73,69 @@ public class RepositoryRestProperties { /** * Content type to use as a default when none is specified. */ - private MediaType defaultMediaType; + private @Nullable MediaType defaultMediaType; /** * Whether to return a response body after creating an entity. */ - private Boolean returnBodyOnCreate; + private @Nullable Boolean returnBodyOnCreate; /** * Whether to return a response body after updating an entity. */ - private Boolean returnBodyOnUpdate; + private @Nullable Boolean returnBodyOnUpdate; /** * Whether to enable enum value translation through the Spring Data REST default * resource bundle. */ - private Boolean enableEnumTranslation; + private @Nullable Boolean enableEnumTranslation; - public String getBasePath() { + public @Nullable String getBasePath() { return this.basePath; } - public void setBasePath(String basePath) { + public void setBasePath(@Nullable String basePath) { this.basePath = basePath; } - public Integer getDefaultPageSize() { + public @Nullable Integer getDefaultPageSize() { return this.defaultPageSize; } - public void setDefaultPageSize(Integer defaultPageSize) { + public void setDefaultPageSize(@Nullable Integer defaultPageSize) { this.defaultPageSize = defaultPageSize; } - public Integer getMaxPageSize() { + public @Nullable Integer getMaxPageSize() { return this.maxPageSize; } - public void setMaxPageSize(Integer maxPageSize) { + public void setMaxPageSize(@Nullable Integer maxPageSize) { this.maxPageSize = maxPageSize; } - public String getPageParamName() { + public @Nullable String getPageParamName() { return this.pageParamName; } - public void setPageParamName(String pageParamName) { + public void setPageParamName(@Nullable String pageParamName) { this.pageParamName = pageParamName; } - public String getLimitParamName() { + public @Nullable String getLimitParamName() { return this.limitParamName; } - public void setLimitParamName(String limitParamName) { + public void setLimitParamName(@Nullable String limitParamName) { this.limitParamName = limitParamName; } - public String getSortParamName() { + public @Nullable String getSortParamName() { return this.sortParamName; } - public void setSortParamName(String sortParamName) { + public void setSortParamName(@Nullable String sortParamName) { this.sortParamName = sortParamName; } @@ -145,35 +147,35 @@ public class RepositoryRestProperties { this.detectionStrategy = detectionStrategy; } - public MediaType getDefaultMediaType() { + public @Nullable MediaType getDefaultMediaType() { return this.defaultMediaType; } - public void setDefaultMediaType(MediaType defaultMediaType) { + public void setDefaultMediaType(@Nullable MediaType defaultMediaType) { this.defaultMediaType = defaultMediaType; } - public Boolean getReturnBodyOnCreate() { + public @Nullable Boolean getReturnBodyOnCreate() { return this.returnBodyOnCreate; } - public void setReturnBodyOnCreate(Boolean returnBodyOnCreate) { + public void setReturnBodyOnCreate(@Nullable Boolean returnBodyOnCreate) { this.returnBodyOnCreate = returnBodyOnCreate; } - public Boolean getReturnBodyOnUpdate() { + public @Nullable Boolean getReturnBodyOnUpdate() { return this.returnBodyOnUpdate; } - public void setReturnBodyOnUpdate(Boolean returnBodyOnUpdate) { + public void setReturnBodyOnUpdate(@Nullable Boolean returnBodyOnUpdate) { this.returnBodyOnUpdate = returnBodyOnUpdate; } - public Boolean getEnableEnumTranslation() { + public @Nullable Boolean getEnableEnumTranslation() { return this.enableEnumTranslation; } - public void setEnableEnumTranslation(Boolean enableEnumTranslation) { + public void setEnableEnumTranslation(@Nullable Boolean enableEnumTranslation) { this.enableEnumTranslation = enableEnumTranslation; } diff --git a/module/spring-boot-data-rest/src/main/java/org/springframework/boot/data/rest/autoconfigure/SpringBootRepositoryRestConfigurer.java b/module/spring-boot-data-rest/src/main/java/org/springframework/boot/data/rest/autoconfigure/SpringBootRepositoryRestConfigurer.java index 479e33023b1..58eadf80ef2 100644 --- a/module/spring-boot-data-rest/src/main/java/org/springframework/boot/data/rest/autoconfigure/SpringBootRepositoryRestConfigurer.java +++ b/module/spring-boot-data-rest/src/main/java/org/springframework/boot/data/rest/autoconfigure/SpringBootRepositoryRestConfigurer.java @@ -17,6 +17,7 @@ package org.springframework.boot.data.rest.autoconfigure; import com.fasterxml.jackson.databind.ObjectMapper; +import org.jspecify.annotations.Nullable; import org.springframework.core.annotation.Order; import org.springframework.data.rest.core.config.RepositoryRestConfiguration; @@ -37,11 +38,11 @@ import org.springframework.web.servlet.config.annotation.CorsRegistry; @SuppressWarnings("removal") class SpringBootRepositoryRestConfigurer implements RepositoryRestConfigurer { - private final Jackson2ObjectMapperBuilder objectMapperBuilder; + private final @Nullable Jackson2ObjectMapperBuilder objectMapperBuilder; private final RepositoryRestProperties properties; - SpringBootRepositoryRestConfigurer(Jackson2ObjectMapperBuilder objectMapperBuilder, + SpringBootRepositoryRestConfigurer(@Nullable Jackson2ObjectMapperBuilder objectMapperBuilder, RepositoryRestProperties properties) { this.objectMapperBuilder = objectMapperBuilder; this.properties = properties; diff --git a/module/spring-boot-data-rest/src/main/java/org/springframework/boot/data/rest/autoconfigure/package-info.java b/module/spring-boot-data-rest/src/main/java/org/springframework/boot/data/rest/autoconfigure/package-info.java index 3bb7cbeaf6b..2385c09293a 100644 --- a/module/spring-boot-data-rest/src/main/java/org/springframework/boot/data/rest/autoconfigure/package-info.java +++ b/module/spring-boot-data-rest/src/main/java/org/springframework/boot/data/rest/autoconfigure/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for Spring Data REST. */ +@NullMarked package org.springframework.boot.data.rest.autoconfigure; + +import org.jspecify.annotations.NullMarked;