Skip to content

Commit 44d119b

Browse files
committed
Migrate to JSpecify annotations for nullability constraints.
Closes #3170
1 parent 9592c50 commit 44d119b

File tree

344 files changed

+1515
-1234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

344 files changed

+1515
-1234
lines changed

src/main/java/org/springframework/data/annotation/AccessType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* @author Oliver Gierke
2929
*/
3030
@Documented
31-
@Target({ ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, })
31+
@Target({ ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD, ElementType.METHOD })
3232
@Retention(RetentionPolicy.RUNTIME)
3333
public @interface AccessType {
3434

@@ -40,4 +40,5 @@
4040
enum Type {
4141
FIELD, PROPERTY;
4242
}
43+
4344
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Core annotations being used by Spring Data.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.annotation;

src/main/java/org/springframework/data/aot/AotContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
import java.util.Set;
2323
import java.util.function.Consumer;
2424

25+
import org.jspecify.annotations.Nullable;
26+
2527
import org.springframework.beans.factory.BeanFactory;
2628
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
2729
import org.springframework.beans.factory.config.BeanDefinition;
2830
import org.springframework.beans.factory.config.BeanReference;
2931
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
3032
import org.springframework.beans.factory.support.RootBeanDefinition;
3133
import org.springframework.data.util.TypeScanner;
32-
import org.springframework.lang.Nullable;
3334
import org.springframework.util.Assert;
3435

3536
/**

src/main/java/org/springframework/data/aot/AuditingBeanRegistrationAotProcessor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.springframework.data.aot;
1717

18+
import org.jspecify.annotations.Nullable;
19+
1820
import org.springframework.aop.SpringProxy;
1921
import org.springframework.aop.framework.Advised;
2022
import org.springframework.aot.hint.RuntimeHints;
@@ -26,7 +28,6 @@
2628
import org.springframework.data.domain.AuditorAware;
2729
import org.springframework.data.domain.ReactiveAuditorAware;
2830
import org.springframework.data.util.ReactiveWrappers;
29-
import org.springframework.lang.Nullable;
3031
import org.springframework.util.ClassUtils;
3132

3233
/**

src/main/java/org/springframework/data/aot/DefaultAotContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.List;
2121
import java.util.Optional;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.beans.factory.BeanFactory;
2426
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
2527
import org.springframework.beans.factory.config.BeanDefinition;
@@ -132,7 +134,7 @@ public RootBeanDefinition getRootBeanDefinition() throws NoSuchBeanDefinitionExc
132134
}
133135

134136
@Override
135-
public Class<?> resolveType() {
137+
public @Nullable Class<?> resolveType() {
136138
return factory.getType(beanName, false);
137139
}
138140
}

src/main/java/org/springframework/data/aot/ManagedTypesBeanFactoryInitializationAotProcessor.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.apache.commons.logging.Log;
2222
import org.apache.commons.logging.LogFactory;
23+
import org.jspecify.annotations.Nullable;
2324

2425
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution;
2526
import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor;
@@ -30,7 +31,6 @@
3031
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
3132
import org.springframework.data.domain.ManagedTypes;
3233
import org.springframework.lang.Contract;
33-
import org.springframework.lang.Nullable;
3434
import org.springframework.util.CollectionUtils;
3535
import org.springframework.util.ObjectUtils;
3636

@@ -48,9 +48,9 @@ public class ManagedTypesBeanFactoryInitializationAotProcessor implements BeanFa
4848
private static final Log logger = LogFactory.getLog(ManagedTypesBeanFactoryInitializationAotProcessor.class);
4949

5050
@Override
51-
@Nullable
5251
@Contract("_ -> null")
53-
public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
52+
public @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(
53+
ConfigurableListableBeanFactory beanFactory) {
5454

5555
processManagedTypes(beanFactory);
5656
return null;
@@ -82,12 +82,15 @@ private void postProcessManagedTypes(ConfigurableListableBeanFactory beanFactory
8282
}
8383

8484
Object value = potentiallyWrapToIterable(supplier.get());
85+
String beanClassName = beanDefinition.getBeanClassName();
8586

86-
BeanDefinition beanDefinitionReplacement = newManagedTypeBeanDefinition(beanDefinition.getBeanClassName(),
87-
value);
87+
if (beanClassName != null) {
8888

89-
registry.removeBeanDefinition(beanName);
90-
registry.registerBeanDefinition(beanName, beanDefinitionReplacement);
89+
BeanDefinition beanDefinitionReplacement = newManagedTypeBeanDefinition(beanClassName, value);
90+
91+
registry.removeBeanDefinition(beanName);
92+
registry.registerBeanDefinition(beanName, beanDefinitionReplacement);
93+
}
9194
}
9295
}
9396
}

src/main/java/org/springframework/data/aot/ManagedTypesBeanRegistrationAotProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
import org.apache.commons.logging.Log;
2323
import org.apache.commons.logging.LogFactory;
24+
import org.jspecify.annotations.Nullable;
25+
2426
import org.springframework.aot.generate.GenerationContext;
2527
import org.springframework.beans.factory.BeanCreationException;
2628
import org.springframework.beans.factory.BeanFactory;
@@ -34,7 +36,6 @@
3436
import org.springframework.data.util.QTypeContributor;
3537
import org.springframework.data.util.TypeContributor;
3638
import org.springframework.data.util.TypeUtils;
37-
import org.springframework.lang.Nullable;
3839
import org.springframework.util.ClassUtils;
3940
import org.springframework.util.StringUtils;
4041

@@ -61,7 +62,7 @@ public String getModuleIdentifier() {
6162
}
6263

6364
@Override
64-
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
65+
public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {
6566

6667
if (!isMatch(registeredBean.getBeanClass(), registeredBean.getBeanName())) {
6768
return null;

src/main/java/org/springframework/data/aot/ManagedTypesRegistrationAotContribution.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import javax.lang.model.element.Modifier;
2424

25+
import org.jspecify.annotations.Nullable;
26+
2527
import org.springframework.aot.generate.AccessControl;
2628
import org.springframework.aot.generate.GeneratedMethod;
2729
import org.springframework.aot.generate.GenerationContext;
@@ -41,7 +43,6 @@
4143
import org.springframework.javapoet.ParameterizedTypeName;
4244
import org.springframework.javapoet.TypeName;
4345
import org.springframework.javapoet.WildcardTypeName;
44-
import org.springframework.lang.Nullable;
4546
import org.springframework.util.ClassUtils;
4647
import org.springframework.util.ObjectUtils;
4748
import org.springframework.util.ReflectionUtils;

src/main/java/org/springframework/data/aot/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
* Support for registering the need for reflection, resources, java serialization and proxies at runtime for Ahead of
33
* Time compilation.
44
*/
5-
@org.springframework.lang.NonNullApi
5+
@org.jspecify.annotations.NullMarked
66
package org.springframework.data.aot;

src/main/java/org/springframework/data/auditing/AuditableBeanWrapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
import java.time.temporal.TemporalAccessor;
1919
import java.util.Optional;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.lang.Contract;
22-
import org.springframework.lang.Nullable;
2324

2425
/**
2526
* Interface to abstract the ways setting the auditing information can be implemented.

0 commit comments

Comments
 (0)