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,7 +16,7 @@
package org.springframework.beans.testfixture.beans;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* Simple nested test bean used for testing bean factories, AOP framework etc.

View File

@@ -18,7 +18,7 @@ package org.springframework.beans.testfixture.beans;
import java.util.Objects;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
/**
* @author Rob Harrop

View File

@@ -18,7 +18,8 @@ package org.springframework.beans.testfixture.beans;
import java.io.Serializable;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.ObjectUtils;
/**

View File

@@ -27,10 +27,11 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**

View File

@@ -18,8 +18,9 @@ package org.springframework.beans.testfixture.beans.factory.aot;
import java.util.function.Consumer;
import org.jspecify.annotations.Nullable;
import org.springframework.javapoet.TypeSpec;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -31,8 +32,7 @@ import org.springframework.util.Assert;
*/
public class DeferredTypeBuilder implements Consumer<TypeSpec.Builder> {
@Nullable
private Consumer<TypeSpec.Builder> type;
private @Nullable Consumer<TypeSpec.Builder> type;
@Override
public void accept(TypeSpec.Builder type) {

View File

@@ -16,9 +16,10 @@
package org.springframework.beans.testfixture.beans.factory.aot;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.lang.Nullable;
/**
* A public {@link FactoryBean} with a generic type.
@@ -33,15 +34,13 @@ public class GenericFactoryBean<T> implements FactoryBean<T> {
this.beanType = beanType;
}
@Nullable
@Override
public T getObject() throws Exception {
public @Nullable T getObject() throws Exception {
return BeanUtils.instantiateClass(this.beanType);
}
@Nullable
@Override
public Class<?> getObjectType() {
public @Nullable Class<?> getObjectType() {
return this.beanType;
}
}

View File

@@ -1,9 +1,7 @@
/**
* Test fixtures for bean factories AOT support.
*/
@NonNullApi
@NonNullFields
@NullMarked
package org.springframework.beans.testfixture.beans.factory.aot;
import org.springframework.lang.NonNullApi;
import org.springframework.lang.NonNullFields;
import org.jspecify.annotations.NullMarked;