diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OnFailureConditionReportContextCustomizerFactory.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OnFailureConditionReportContextCustomizerFactory.java index 0df74e76861..4620c8069fd 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OnFailureConditionReportContextCustomizerFactory.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OnFailureConditionReportContextCustomizerFactory.java @@ -19,6 +19,8 @@ package org.springframework.boot.test.autoconfigure; import java.util.List; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport; import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportMessage; import org.springframework.boot.context.event.ApplicationFailedEvent; @@ -89,7 +91,7 @@ class OnFailureConditionReportContextCustomizerFactory implements ContextCustomi } } - private static boolean shouldPrintReport(ConfigurableApplicationContext context) { + private static boolean shouldPrintReport(@Nullable ConfigurableApplicationContext context) { return (context == null) || context.getEnvironment() .getProperty("spring.test.print-condition-evaluation-report", Boolean.class, true); } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactory.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactory.java index 25dfdfa8c8b..f07472ebac6 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactory.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/OverrideAutoConfigurationContextCustomizerFactory.java @@ -18,6 +18,8 @@ package org.springframework.boot.test.autoconfigure; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.AotDetector; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.util.TestPropertyValues; @@ -37,7 +39,7 @@ import org.springframework.test.context.TestContextAnnotationUtils; class OverrideAutoConfigurationContextCustomizerFactory implements ContextCustomizerFactory { @Override - public ContextCustomizer createContextCustomizer(Class testClass, + public @Nullable ContextCustomizer createContextCustomizer(Class testClass, List configurationAttributes) { if (AotDetector.useGeneratedArtifacts()) { return null; @@ -59,7 +61,7 @@ class OverrideAutoConfigurationContextCustomizerFactory implements ContextCustom } @Override - public boolean equals(Object obj) { + public boolean equals(@Nullable Object obj) { return (obj != null) && (obj.getClass() == getClass()); } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/TestSliceTestContextBootstrapper.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/TestSliceTestContextBootstrapper.java index 32ba005b058..111aa48c02f 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/TestSliceTestContextBootstrapper.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/TestSliceTestContextBootstrapper.java @@ -18,6 +18,8 @@ package org.springframework.boot.test.autoconfigure; import java.lang.annotation.Annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.test.context.SpringBootTestContextBootstrapper; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.MergedAnnotation; @@ -40,16 +42,17 @@ public abstract class TestSliceTestContextBootstrapper ext @SuppressWarnings("unchecked") protected TestSliceTestContextBootstrapper() { - this.annotationType = (Class) ResolvableType.forClass(getClass()) + Class annotationType = (Class) ResolvableType.forClass(getClass()) .as(TestSliceTestContextBootstrapper.class) .getGeneric(0) .resolve(); - Assert.notNull(this.annotationType, "'%s' doesn't contain type parameter of '%s'" - .formatted(getClass().getName(), TestSliceTestContextBootstrapper.class.getName())); + Assert.notNull(annotationType, "'%s' doesn't contain type parameter of '%s'".formatted(getClass().getName(), + TestSliceTestContextBootstrapper.class.getName())); + this.annotationType = annotationType; } @Override - protected String[] getProperties(Class testClass) { + protected String @Nullable [] getProperties(Class testClass) { MergedAnnotation annotation = MergedAnnotations.search(SearchStrategy.TYPE_HIERARCHY) .withEnclosingClasses(TestContextAnnotationUtils::searchEnclosingClass) .from(testClass) diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/actuate/observability/ObservabilityContextCustomizerFactory.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/actuate/observability/ObservabilityContextCustomizerFactory.java index de0df86d8f6..9336eeee936 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/actuate/observability/ObservabilityContextCustomizerFactory.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/actuate/observability/ObservabilityContextCustomizerFactory.java @@ -19,6 +19,8 @@ package org.springframework.boot.test.autoconfigure.actuate.observability; import java.util.List; import java.util.Objects; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.Environment; @@ -50,9 +52,9 @@ class ObservabilityContextCustomizerFactory implements ContextCustomizerFactory private static class DisableObservabilityContextCustomizer implements ContextCustomizer { - private final AutoConfigureObservability annotation; + private final @Nullable AutoConfigureObservability annotation; - DisableObservabilityContextCustomizer(AutoConfigureObservability annotation) { + DisableObservabilityContextCustomizer(@Nullable AutoConfigureObservability annotation) { this.annotation = annotation; } @@ -85,7 +87,7 @@ class ObservabilityContextCustomizerFactory implements ContextCustomizerFactory } @Override - public boolean equals(Object o) { + public boolean equals(@Nullable Object o) { if (this == o) { return true; } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/actuate/observability/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/actuate/observability/package-info.java index 9cd09967cb8..a59f2ea52c6 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/actuate/observability/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/actuate/observability/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for handling observability in tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.actuate.observability; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/core/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/core/package-info.java index f91b0cc7c0b..a8352c5acc3 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/core/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/core/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for core parts common to most Spring Boot applications. */ +@NullMarked package org.springframework.boot.test.autoconfigure.core; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/cassandra/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/cassandra/package-info.java index da14c469601..8d02e031a6b 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/cassandra/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/cassandra/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for Data Cassandra tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.data.cassandra; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/couchbase/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/couchbase/package-info.java index bb2467766cf..c6ce2c327d1 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/couchbase/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/couchbase/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for Data Couchbase tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.data.couchbase; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/elasticsearch/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/elasticsearch/package-info.java index 6a059356d54..38dfd4e6334 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/elasticsearch/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/elasticsearch/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for Data Elasticsearch tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.data.elasticsearch; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/package-info.java index aa7154dce76..fe0bb75b0bb 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/jdbc/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for Data JDBC tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.data.jdbc; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/package-info.java index b003cd403f8..08244bb4d0c 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/ldap/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for Data LDAP tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.data.ldap; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/package-info.java index 46cecb40ba2..d69f90a45cd 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/mongo/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for Data Mongo tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.data.mongo; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/package-info.java index 3e9085cc096..8ed23c35b67 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/neo4j/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for Data Neo4j tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.data.neo4j; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/r2dbc/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/r2dbc/package-info.java index e3e2a2016eb..33088559acb 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/r2dbc/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/r2dbc/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for Data R2DBC tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.data.r2dbc; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/package-info.java index a5406706acd..4a3d8698dae 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/data/redis/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for Data Redis tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.data.redis; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/AnnotationCustomizableTypeExcludeFilter.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/AnnotationCustomizableTypeExcludeFilter.java index ed4a0bfd113..fe1f1ff67ab 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/AnnotationCustomizableTypeExcludeFilter.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/AnnotationCustomizableTypeExcludeFilter.java @@ -22,6 +22,8 @@ import java.util.Arrays; import java.util.Objects; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.boot.context.TypeExcludeFilter; import org.springframework.context.annotation.ComponentScan.Filter; @@ -41,6 +43,7 @@ import org.springframework.util.ObjectUtils; public abstract class AnnotationCustomizableTypeExcludeFilter extends TypeExcludeFilter implements BeanClassLoaderAware { + @SuppressWarnings("NullAway.Init") private ClassLoader classLoader; @Override @@ -113,11 +116,11 @@ public abstract class AnnotationCustomizableTypeExcludeFilter extends TypeExclud } @Override - public boolean equals(Object obj) { + public boolean equals(@Nullable Object obj) { if (this == obj) { return true; } - if (getClass() != obj.getClass()) { + if (obj == null || getClass() != obj.getClass()) { return false; } AnnotationCustomizableTypeExcludeFilter other = (AnnotationCustomizableTypeExcludeFilter) obj; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/StandardAnnotationCustomizableTypeExcludeFilter.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/StandardAnnotationCustomizableTypeExcludeFilter.java index 1ac2d316cd2..561db64edf6 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/StandardAnnotationCustomizableTypeExcludeFilter.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/StandardAnnotationCustomizableTypeExcludeFilter.java @@ -26,6 +26,7 @@ import org.springframework.core.ResolvableType; import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; +import org.springframework.util.Assert; /** * {@link AnnotationCustomizableTypeExcludeFilter} that can be used to any test annotation @@ -90,7 +91,9 @@ public abstract class StandardAnnotationCustomizableTypeExcludeFilter getAnnotationType() { ResolvableType type = ResolvableType.forClass(StandardAnnotationCustomizableTypeExcludeFilter.class, getClass()); - return (Class) type.resolveGeneric(); + Class generic = (Class) type.resolveGeneric(); + Assert.state(generic != null, "'generic' must not be null"); + return generic; } } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/TypeExcludeFiltersContextCustomizer.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/TypeExcludeFiltersContextCustomizer.java index 81b50085480..8b6604c843c 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/TypeExcludeFiltersContextCustomizer.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/TypeExcludeFiltersContextCustomizer.java @@ -22,6 +22,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.context.TypeExcludeFilter; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.type.classreading.MetadataReader; @@ -70,7 +72,7 @@ class TypeExcludeFiltersContextCustomizer implements ContextCustomizer { } @Override - public boolean equals(Object obj) { + public boolean equals(@Nullable Object obj) { return (obj != null) && (getClass() == obj.getClass()) && this.filters.equals(((TypeExcludeFiltersContextCustomizer) obj).filters); } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/TypeExcludeFiltersContextCustomizerFactory.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/TypeExcludeFiltersContextCustomizerFactory.java index e0b79835d0a..da961705ee2 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/TypeExcludeFiltersContextCustomizerFactory.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/TypeExcludeFiltersContextCustomizerFactory.java @@ -20,6 +20,8 @@ import java.util.Arrays; import java.util.LinkedHashSet; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.AotDetector; import org.springframework.boot.context.TypeExcludeFilter; import org.springframework.test.context.ContextConfigurationAttributes; @@ -27,7 +29,6 @@ import org.springframework.test.context.ContextCustomizer; import org.springframework.test.context.ContextCustomizerFactory; import org.springframework.test.context.TestContextAnnotationUtils; import org.springframework.test.context.TestContextAnnotationUtils.AnnotationDescriptor; -import org.springframework.util.ObjectUtils; /** * {@link ContextCustomizerFactory} to support @@ -41,17 +42,17 @@ class TypeExcludeFiltersContextCustomizerFactory implements ContextCustomizerFac private static final Class[] NO_FILTERS = {}; @Override - public ContextCustomizer createContextCustomizer(Class testClass, + public @Nullable ContextCustomizer createContextCustomizer(Class testClass, List configurationAttributes) { if (AotDetector.useGeneratedArtifacts()) { return null; } AnnotationDescriptor descriptor = TestContextAnnotationUtils .findAnnotationDescriptor(testClass, TypeExcludeFilters.class); - Class[] filterClasses = (descriptor != null) ? descriptor.getAnnotation().value() : NO_FILTERS; - if (ObjectUtils.isEmpty(filterClasses)) { + if (descriptor == null) { return null; } + Class[] filterClasses = descriptor.getAnnotation().value(); return createContextCustomizer(descriptor.getRootDeclaringClass(), filterClasses); } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/package-info.java index 3f55a77401b..159cc6ad58b 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/filter/package-info.java @@ -18,4 +18,7 @@ * Helper utilities for using {@link org.springframework.boot.context.TypeExcludeFilter} * with auto-configured tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.filter; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/package-info.java index 09f04bc21bf..f207b538eb6 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for GraphQL testing. */ +@NullMarked package org.springframework.boot.test.autoconfigure.graphql; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/package-info.java index f6e750a8b2c..ed68ff723ab 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/graphql/tester/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for GraphQL tester. */ +@NullMarked package org.springframework.boot.test.autoconfigure.graphql.tester; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java index 1eac6a8a39a..fd0190229c6 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/TestDatabaseAutoConfiguration.java @@ -25,6 +25,7 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aot.AotDetector; import org.springframework.beans.BeansException; @@ -64,6 +65,7 @@ import org.springframework.core.env.PropertySource; import org.springframework.core.type.MethodMetadata; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -153,7 +155,8 @@ public final class TestDatabaseAutoConfiguration { return beanDefinition; } - private BeanDefinitionHolder getDataSourceBeanDefinition(ConfigurableListableBeanFactory beanFactory) { + private @Nullable BeanDefinitionHolder getDataSourceBeanDefinition( + ConfigurableListableBeanFactory beanFactory) { String[] beanNames = beanFactory.getBeanNamesForType(DataSource.class); if (ObjectUtils.isEmpty(beanNames)) { logger.warn("No DataSource beans found, embedded version will not be used"); @@ -228,7 +231,7 @@ public final class TestDatabaseAutoConfiguration { return false; } - private boolean isDynamicValuesPropertySource(PropertySource propertySource) { + private boolean isDynamicValuesPropertySource(@Nullable PropertySource propertySource) { return propertySource != null && DYNAMIC_VALUES_PROPERTY_SOURCE_CLASS.equals(propertySource.getClass().getName()); } @@ -242,8 +245,10 @@ public final class TestDatabaseAutoConfiguration { static class EmbeddedDataSourceFactoryBean implements FactoryBean, EnvironmentAware, InitializingBean { + @SuppressWarnings("NullAway.Init") private EmbeddedDataSourceFactory factory; + @SuppressWarnings("NullAway.Init") private EmbeddedDatabase embeddedDatabase; @Override @@ -292,7 +297,9 @@ public final class TestDatabaseAutoConfiguration { "Failed to replace DataSource with an embedded database for tests. If " + "you want an embedded database please put a supported one " + "on the classpath or tune the replace attribute of @AutoConfigureTestDatabase."); - return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(connection.getType()).build(); + EmbeddedDatabaseType type = connection.getType(); + Assert.state(type != null, "'type' must not be null"); + return new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(type).build(); } } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/package-info.java index cbb1b1023a5..ad76a3ead42 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jdbc/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for JDBC tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.jdbc; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/package-info.java index ed9aafc5c33..f7832f9a2c1 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/jooq/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for jOOQ tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.jooq; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfiguration.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfiguration.java index e14f1983778..ded98aa1ff6 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfiguration.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/JsonTestersAutoConfiguration.java @@ -18,10 +18,12 @@ package org.springframework.boot.test.autoconfigure.json; import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.Method; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.gson.Gson; import jakarta.json.bind.Jsonb; +import org.jspecify.annotations.Nullable; import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.MemberCategory; @@ -49,6 +51,7 @@ import org.springframework.context.annotation.ImportRuntimeHints; import org.springframework.context.annotation.Scope; import org.springframework.core.ResolvableType; import org.springframework.test.util.ReflectionTestUtils; +import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; /** @@ -154,9 +157,9 @@ public final class JsonTestersAutoConfiguration { private final Class objectType; - private final M marshaller; + private final @Nullable M marshaller; - JsonTesterFactoryBean(Class objectType, M marshaller) { + JsonTesterFactoryBean(Class objectType, @Nullable M marshaller) { this.objectType = objectType; this.marshaller = marshaller; } @@ -232,12 +235,12 @@ public final class JsonTestersAutoConfiguration { } @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { ReflectionHints reflection = hints.reflection(); reflection.registerType(this.tester, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); - reflection.registerMethod( - ReflectionUtils.findMethod(this.tester, "initialize", Class.class, ResolvableType.class), - ExecutableMode.INVOKE); + Method method = ReflectionUtils.findMethod(this.tester, "initialize", Class.class, ResolvableType.class); + Assert.state(method != null, "'method' must not be null"); + reflection.registerMethod(method, ExecutableMode.INVOKE); } } @@ -245,11 +248,12 @@ public final class JsonTestersAutoConfiguration { static class BasicJsonTesterRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { ReflectionHints reflection = hints.reflection(); reflection.registerType(BasicJsonTester.class, MemberCategory.INVOKE_DECLARED_CONSTRUCTORS); - reflection.registerMethod(ReflectionUtils.findMethod(BasicJsonTester.class, "initialize", Class.class), - ExecutableMode.INVOKE); + Method method = ReflectionUtils.findMethod(BasicJsonTester.class, "initialize", Class.class); + Assert.state(method != null, "'method' must not be null"); + reflection.registerMethod(method, ExecutableMode.INVOKE); } } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/package-info.java index 6c442eba027..f71c02793d4 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/json/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for JSON tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.json; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManager.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManager.java index 3d1d434ebd2..c983ff1a9b9 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManager.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/TestEntityManager.java @@ -19,6 +19,7 @@ package org.springframework.boot.test.autoconfigure.orm.jpa; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.PersistenceUnitUtil; +import org.jspecify.annotations.Nullable; import org.springframework.orm.jpa.EntityManagerFactoryUtils; import org.springframework.util.Assert; @@ -55,7 +56,7 @@ public class TestEntityManager { * @param entity the source entity * @return the ID of the newly persisted entity */ - public Object persistAndGetId(Object entity) { + public @Nullable Object persistAndGetId(Object entity) { persist(entity); return getId(entity); } @@ -72,7 +73,7 @@ public class TestEntityManager { * @param idType the ID type * @return the ID of the newly persisted entity */ - public T persistAndGetId(Object entity, Class idType) { + public @Nullable T persistAndGetId(Object entity, Class idType) { persist(entity); return getId(entity, idType); } @@ -159,7 +160,7 @@ public class TestEntityManager { * @return the found entity or {@code null} if the entity does not exist * @see #getId(Object) */ - public E find(Class entityClass, Object primaryKey) { + public @Nullable E find(Class entityClass, Object primaryKey) { return getEntityManager().find(entityClass, primaryKey); } @@ -207,7 +208,7 @@ public class TestEntityManager { * @return the ID of the entity or {@code null} * @see #getId(Object, Class) */ - public Object getId(Object entity) { + public @Nullable Object getId(Object entity) { return this.entityManagerFactory.getPersistenceUnitUtil().getIdentifier(entity); } @@ -221,7 +222,7 @@ public class TestEntityManager { * @see #getId(Object) */ @SuppressWarnings("unchecked") - public T getId(Object entity, Class idType) { + public @Nullable T getId(Object entity, Class idType) { Object id = getId(entity); Assert.isInstanceOf(idType, id, "ID mismatch:"); return (T) id; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/package-info.java index 087105342cd..5b0d4b8c8d1 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/orm/jpa/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for Data JPA tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.orm.jpa; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/package-info.java index 7a796fd386e..d091b6e2699 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/package-info.java @@ -17,4 +17,7 @@ /** * Test auto-configuration support. */ +@NullMarked package org.springframework.boot.test.autoconfigure; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java index 6a67cc26620..0b52b6e4a24 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/AnnotationsPropertySource.java @@ -25,6 +25,8 @@ import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; + import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotationPredicates; import org.springframework.core.annotation.MergedAnnotations; @@ -152,7 +154,7 @@ public class AnnotationsPropertySource extends EnumerablePropertySource } @Override - public Object getProperty(String name) { + public @Nullable Object getProperty(String name) { return this.properties.get(name); } @@ -166,7 +168,7 @@ public class AnnotationsPropertySource extends EnumerablePropertySource } @Override - public boolean equals(Object obj) { + public boolean equals(@Nullable Object obj) { if (obj == this) { return true; } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/PropertyMappingContextCustomizer.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/PropertyMappingContextCustomizer.java index a727e6c47ca..8c0a430dfde 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/PropertyMappingContextCustomizer.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/PropertyMappingContextCustomizer.java @@ -19,6 +19,8 @@ package org.springframework.boot.test.autoconfigure.properties; import java.util.Set; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.context.ConfigurableApplicationContext; @@ -57,7 +59,7 @@ class PropertyMappingContextCustomizer implements ContextCustomizer { } @Override - public boolean equals(Object obj) { + public boolean equals(@Nullable Object obj) { return (obj != null) && (getClass() == obj.getClass()) && this.propertySource.equals(((PropertyMappingContextCustomizer) obj).propertySource); } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/package-info.java index 49e34457c93..bf72f37d108 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/properties/package-info.java @@ -17,4 +17,7 @@ /** * Support for mapping annotation attribute values in the Spring {@code Environment}. */ +@NullMarked package org.springframework.boot.test.autoconfigure.properties; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsMockMvcBuilderCustomizer.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsMockMvcBuilderCustomizer.java index 9f7e9472daf..58d676b177c 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsMockMvcBuilderCustomizer.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsMockMvcBuilderCustomizer.java @@ -16,6 +16,8 @@ package org.springframework.boot.test.autoconfigure.restdocs; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.InitializingBean; import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.boot.test.autoconfigure.web.servlet.MockMvcBuilderCustomizer; @@ -36,10 +38,10 @@ public class RestDocsMockMvcBuilderCustomizer implements InitializingBean, MockM private final MockMvcRestDocumentationConfigurer delegate; - private final RestDocumentationResultHandler resultHandler; + private final @Nullable RestDocumentationResultHandler resultHandler; RestDocsMockMvcBuilderCustomizer(RestDocsProperties properties, MockMvcRestDocumentationConfigurer delegate, - RestDocumentationResultHandler resultHandler) { + @Nullable RestDocumentationResultHandler resultHandler) { this.properties = properties; this.delegate = delegate; this.resultHandler = resultHandler; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsProperties.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsProperties.java index eb17dbb0340..97aee9c3cb2 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsProperties.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsProperties.java @@ -16,6 +16,8 @@ package org.springframework.boot.test.autoconfigure.restdocs; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.context.properties.ConfigurationProperties; /** @@ -32,39 +34,39 @@ public class RestDocsProperties { /** * The URI scheme for to use (for example http). */ - private String uriScheme; + private @Nullable String uriScheme; /** * The URI host to use. */ - private String uriHost; + private @Nullable String uriHost; /** * The URI port to use. */ - private Integer uriPort; + private @Nullable Integer uriPort; - public String getUriScheme() { + public @Nullable String getUriScheme() { return this.uriScheme; } - public void setUriScheme(String uriScheme) { + public void setUriScheme(@Nullable String uriScheme) { this.uriScheme = uriScheme; } - public String getUriHost() { + public @Nullable String getUriHost() { return this.uriHost; } - public void setUriHost(String uriHost) { + public void setUriHost(@Nullable String uriHost) { this.uriHost = uriHost; } - public Integer getUriPort() { + public @Nullable Integer getUriPort() { return this.uriPort; } - public void setUriPort(Integer uriPort) { + public void setUriPort(@Nullable Integer uriPort) { this.uriPort = uriPort; } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsTestExecutionListener.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsTestExecutionListener.java index 22f2822ab97..f651a5ec94d 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsTestExecutionListener.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsTestExecutionListener.java @@ -16,6 +16,8 @@ package org.springframework.boot.test.autoconfigure.restdocs; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.core.Ordered; import org.springframework.restdocs.ManualRestDocumentation; @@ -72,7 +74,7 @@ public class RestDocsTestExecutionListener extends AbstractTestExecutionListener } } - private ManualRestDocumentation findManualRestDocumentation(TestContext testContext) { + private @Nullable ManualRestDocumentation findManualRestDocumentation(TestContext testContext) { try { return testContext.getApplicationContext().getBean(ManualRestDocumentation.class); } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsWebTestClientBuilderCustomizer.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsWebTestClientBuilderCustomizer.java index 5058a289e46..527cc155be8 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsWebTestClientBuilderCustomizer.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocsWebTestClientBuilderCustomizer.java @@ -16,6 +16,8 @@ package org.springframework.boot.test.autoconfigure.restdocs; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.web.server.test.client.reactive.WebTestClientBuilderCustomizer; import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentationConfigurer; import org.springframework.test.web.reactive.server.WebTestClient; @@ -57,7 +59,7 @@ class RestDocsWebTestClientBuilderCustomizer implements WebTestClientBuilderCust builder.baseUrl(baseUrl); } - private boolean isStandardPort(String scheme, Integer port) { + private boolean isStandardPort(@Nullable String scheme, @Nullable Integer port) { if (port == null) { return true; } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocumentationContextProviderRegistrar.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocumentationContextProviderRegistrar.java index a81552d3530..de2e9858c33 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocumentationContextProviderRegistrar.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/RestDocumentationContextProviderRegistrar.java @@ -18,11 +18,14 @@ package org.springframework.boot.test.autoconfigure.restdocs; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.core.type.AnnotationMetadata; import org.springframework.restdocs.ManualRestDocumentation; +import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** @@ -36,10 +39,11 @@ class RestDocumentationContextProviderRegistrar implements ImportBeanDefinitionR @Override public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { - Map annotationAttributes = importingClassMetadata + Map annotationAttributes = importingClassMetadata .getAnnotationAttributes(AutoConfigureRestDocs.class.getName()); BeanDefinitionBuilder definitionBuilder = BeanDefinitionBuilder .rootBeanDefinition(ManualRestDocumentation.class); + Assert.state(annotationAttributes != null, "'annotationAttributes' must not be null"); String outputDir = (String) annotationAttributes.get("outputDir"); if (StringUtils.hasText(outputDir)) { definitionBuilder.addConstructorArgValue(outputDir); diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/package-info.java index 08707d8bc97..a139c6f08be 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/restdocs/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for tests using Spring REST Docs. */ +@NullMarked package org.springframework.boot.test.autoconfigure.restdocs; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/package-info.java index b5f76041195..592f4f6f42f 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/client/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for web clients. */ +@NullMarked package org.springframework.boot.test.autoconfigure.web.client; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/SpringBootWebTestClientBuilderCustomizer.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/SpringBootWebTestClientBuilderCustomizer.java index 0f9bbc4f1cf..228c3d8b7ac 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/SpringBootWebTestClientBuilderCustomizer.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/SpringBootWebTestClientBuilderCustomizer.java @@ -20,6 +20,8 @@ import java.time.Duration; import java.util.Collection; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.boot.http.codec.CodecCustomizer; import org.springframework.boot.web.server.test.client.reactive.WebTestClientBuilderCustomizer; import org.springframework.http.codec.ClientCodecConfigurer; @@ -41,7 +43,7 @@ public class SpringBootWebTestClientBuilderCustomizer implements WebTestClientBu private final Collection codecCustomizers; - private Duration timeout; + private @Nullable Duration timeout; /** * Create a new {@code SpringBootWebTestClientBuilderCustomizer} that will configure @@ -52,7 +54,7 @@ public class SpringBootWebTestClientBuilderCustomizer implements WebTestClientBu this.codecCustomizers = codecCustomizers; } - public void setTimeout(Duration timeout) { + public void setTimeout(@Nullable Duration timeout) { this.timeout = timeout; } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/package-info.java index 6fd9f5735fd..f942576e965 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/reactive/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for reactive web tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.web.reactive; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java index cd4c324a25e..9dd1ed9c650 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/SpringBootMockMvcBuilderCustomizer.java @@ -29,6 +29,7 @@ import jakarta.servlet.Filter; import jakarta.servlet.annotation.WebInitParam; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; @@ -99,7 +100,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi } } - private ResultHandler getPrintHandler() { + private @Nullable ResultHandler getPrintHandler() { LinesWriter writer = getLinesWriter(); if (writer == null) { return null; @@ -110,7 +111,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi return new LinesWritingResultHandler(writer); } - private LinesWriter getLinesWriter() { + private @Nullable LinesWriter getLinesWriter() { if (this.print == MockMvcPrint.NONE) { return null; } @@ -129,8 +130,9 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi } private void addFilter(ConfigurableMockMvcBuilder builder, AbstractFilterRegistrationBean registration) { - Filter filter = registration.getFilter(); Collection urls = registration.getUrlPatterns(); + Filter filter = registration.getFilter(); + Assert.state(filter != null, "'filter' must not be null"); builder.addFilter(filter, registration.getFilterName(), registration.getInitParameters(), registration.determineDispatcherTypes(), StringUtils.toStringArray(urls)); } @@ -199,7 +201,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi } @Override - public void printValue(String label, Object value) { + public void printValue(String label, @Nullable Object value) { if (value != null && value.getClass().isArray()) { value = CollectionUtils.arrayToList(value); } @@ -259,7 +261,7 @@ public class SpringBootMockMvcBuilderCustomizer implements MockMvcBuilderCustomi this.delegate.write(this.lines.get()); } - static DeferredLinesWriter get(ApplicationContext applicationContext) { + static @Nullable DeferredLinesWriter get(ApplicationContext applicationContext) { try { return applicationContext.getBean(BEAN_NAME, DeferredLinesWriter.class); } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverContextCustomizer.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverContextCustomizer.java index 5cba7359202..29363645af0 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverContextCustomizer.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverContextCustomizer.java @@ -16,6 +16,8 @@ package org.springframework.boot.test.autoconfigure.web.servlet; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ConfigurableApplicationContext; import org.springframework.test.context.ContextCustomizer; import org.springframework.test.context.MergedContextConfiguration; @@ -35,7 +37,7 @@ class WebDriverContextCustomizer implements ContextCustomizer { } @Override - public boolean equals(Object obj) { + public boolean equals(@Nullable Object obj) { if (obj == this) { return true; } diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverScope.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverScope.java index 232b3eb0bd9..cd6c7e2934a 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverScope.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/WebDriverScope.java @@ -19,6 +19,7 @@ package org.springframework.boot.test.autoconfigure.web.servlet; import java.util.HashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.WebDriver; import org.springframework.beans.factory.ObjectFactory; @@ -78,12 +79,12 @@ public class WebDriverScope implements Scope { } @Override - public Object resolveContextualObject(String key) { + public @Nullable Object resolveContextualObject(String key) { return null; } @Override - public String getConversationId() { + public @Nullable String getConversationId() { return null; } @@ -137,7 +138,7 @@ public class WebDriverScope implements Scope { * @param context the application context * @return the web driver scope or {@code null} */ - static WebDriverScope getFrom(ApplicationContext context) { + static @Nullable WebDriverScope getFrom(ApplicationContext context) { if (context instanceof ConfigurableApplicationContext configurableContext) { Scope scope = configurableContext.getBeanFactory().getRegisteredScope(NAME); return (scope instanceof WebDriverScope webDriverScope) ? webDriverScope : null; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/package-info.java index 8e5f06b6be8..dd6c2f5130a 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for Spring MVC tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.web.servlet; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/webservices/client/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/webservices/client/package-info.java index 6bfbb09c554..15a0dedc9fa 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/webservices/client/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/webservices/client/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for web service clients. */ +@NullMarked package org.springframework.boot.test.autoconfigure.webservices.client; + +import org.jspecify.annotations.NullMarked; diff --git a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/webservices/server/package-info.java b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/webservices/server/package-info.java index a880bdf5612..f596133ff82 100644 --- a/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/webservices/server/package-info.java +++ b/module/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/webservices/server/package-info.java @@ -17,4 +17,7 @@ /** * Auto-configuration for web service server tests. */ +@NullMarked package org.springframework.boot.test.autoconfigure.webservices.server; + +import org.jspecify.annotations.NullMarked;