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

+2-1
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
}
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

+2-1
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

+2-1
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

+3-1
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

+10-7
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

+3-2
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

+2-1
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

+1-1
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

+2-1
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.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
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.core.log.LogMessage;
2526
import org.springframework.data.domain.Auditable;
2627
import org.springframework.data.mapping.context.PersistentEntities;
27-
import org.springframework.lang.Nullable;
2828
import org.springframework.util.Assert;
2929

3030
/**

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818
import java.util.Optional;
1919

20-
import org.springframework.lang.Nullable;
20+
import org.jspecify.annotations.Nullable;
21+
2122
import org.springframework.util.ObjectUtils;
2223

2324
/**

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
import java.util.concurrent.ConcurrentHashMap;
2525
import java.util.stream.Stream;
2626

27+
import org.jspecify.annotations.Nullable;
28+
2729
import org.springframework.core.ResolvableType;
2830
import org.springframework.core.convert.ConversionService;
2931
import org.springframework.data.convert.Jsr310Converters;
3032
import org.springframework.data.domain.Auditable;
3133
import org.springframework.data.util.ReflectionUtils;
3234
import org.springframework.format.support.DefaultFormattingConversionService;
33-
import org.springframework.lang.Nullable;
3435
import org.springframework.util.Assert;
3536

3637
/**
@@ -115,7 +116,7 @@ public AuditableInterfaceBeanWrapper(ConversionService conversionService,
115116
}
116117

117118
@Override
118-
public Object setCreatedBy(@Nullable Object value) {
119+
public @Nullable Object setCreatedBy(@Nullable Object value) {
119120

120121
auditable.setCreatedBy(value);
121122
return value;
@@ -130,7 +131,7 @@ public TemporalAccessor setCreatedDate(TemporalAccessor value) {
130131
}
131132

132133
@Override
133-
public Object setLastModifiedBy(Object value) {
134+
public @Nullable Object setLastModifiedBy(@Nullable Object value) {
134135

135136
auditable.setLastModifiedBy(value);
136137

@@ -267,7 +268,7 @@ public ReflectionAuditingBeanWrapper(ConversionService conversionService, T targ
267268
}
268269

269270
@Override
270-
public Object setCreatedBy(@Nullable Object value) {
271+
public @Nullable Object setCreatedBy(@Nullable Object value) {
271272
return setField(metadata.getCreatedByField(), value);
272273
}
273274

@@ -277,7 +278,7 @@ public TemporalAccessor setCreatedDate(TemporalAccessor value) {
277278
}
278279

279280
@Override
280-
public Object setLastModifiedBy(@Nullable Object value) {
281+
public @Nullable Object setLastModifiedBy(@Nullable Object value) {
281282
return setField(metadata.getLastModifiedByField(), value);
282283
}
283284

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import java.util.function.Predicate;
2424
import java.util.stream.Stream;
2525

26+
import org.jspecify.annotations.Nullable;
27+
2628
import org.springframework.core.convert.ConversionService;
2729
import org.springframework.data.annotation.CreatedBy;
2830
import org.springframework.data.annotation.CreatedDate;
@@ -41,7 +43,6 @@
4143
import org.springframework.data.mapping.context.PersistentEntities;
4244
import org.springframework.data.util.Lazy;
4345
import org.springframework.lang.Contract;
44-
import org.springframework.lang.Nullable;
4546
import org.springframework.util.Assert;
4647

4748
/**
@@ -195,7 +196,7 @@ public MappingMetadataAuditableBeanWrapper(
195196
}
196197

197198
@Override
198-
public Object setCreatedBy(Object value) {
199+
public @Nullable Object setCreatedBy(@Nullable Object value) {
199200
return setProperty(metadata.createdByPaths, value);
200201
}
201202

@@ -205,7 +206,7 @@ public TemporalAccessor setCreatedDate(TemporalAccessor value) {
205206
}
206207

207208
@Override
208-
public Object setLastModifiedBy(@Nullable Object value) {
209+
public @Nullable Object setLastModifiedBy(@Nullable Object value) {
209210
return setProperty(metadata.lastModifiedByPaths, value);
210211
}
211212

src/main/java/org/springframework/data/auditing/config/AuditingHandlerBeanDefinitionParser.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.*;
1919

20+
import org.jspecify.annotations.Nullable;
21+
2022
import org.springframework.aop.framework.ProxyFactoryBean;
2123
import org.springframework.aop.target.LazyInitTargetSource;
2224
import org.springframework.beans.factory.config.BeanDefinition;
@@ -45,7 +47,7 @@ public class AuditingHandlerBeanDefinitionParser extends AbstractSingleBeanDefin
4547
private static final String AUDITOR_AWARE_REF = "auditor-aware-ref";
4648

4749
private final String mappingContextBeanName;
48-
private String resolvedBeanName;
50+
private @Nullable String resolvedBeanName;
4951

5052
/**
5153
* Creates a new {@link AuditingHandlerBeanDefinitionParser} to point to a {@link MappingContext} with the given bean
@@ -65,7 +67,7 @@ public AuditingHandlerBeanDefinitionParser(String mappingContextBeanName) {
6567
*
6668
* @return the resolvedBeanName
6769
*/
68-
public String getResolvedBeanName() {
70+
public @Nullable String getResolvedBeanName() {
6971
return resolvedBeanName;
7072
}
7173

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Types to abstract authentication concepts.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.auditing.config;
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* General support for entity auditing.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.auditing;

src/main/java/org/springframework/data/config/ParsingUtils.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
*/
1616
package org.springframework.data.config;
1717

18+
import org.jspecify.annotations.Nullable;
19+
1820
import org.springframework.beans.factory.config.BeanDefinition;
1921
import org.springframework.beans.factory.config.ObjectFactoryCreatingFactoryBean;
2022
import org.springframework.beans.factory.support.AbstractBeanDefinition;
2123
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
2224
import org.springframework.beans.factory.xml.BeanDefinitionParser;
2325
import org.springframework.beans.factory.xml.ParserContext;
24-
import org.springframework.lang.Nullable;
2526
import org.springframework.util.Assert;
2627
import org.springframework.util.StringUtils;
28+
2729
import org.w3c.dom.Element;
2830

2931
/**

src/main/java/org/springframework/data/config/TypeFilterParser.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.HashSet;
2121
import java.util.regex.Pattern;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.beans.BeanUtils;
2426
import org.springframework.beans.FatalBeanException;
2527
import org.springframework.beans.factory.parsing.ReaderContext;
@@ -30,7 +32,6 @@
3032
import org.springframework.core.type.filter.AssignableTypeFilter;
3133
import org.springframework.core.type.filter.RegexPatternTypeFilter;
3234
import org.springframework.core.type.filter.TypeFilter;
33-
import org.springframework.lang.Nullable;
3435
import org.springframework.util.Assert;
3536

3637
import org.w3c.dom.Element;
@@ -101,7 +102,8 @@ public Collection<TypeFilter> parseTypeFilters(Element element, Type type) {
101102
try {
102103
filters.add(createTypeFilter(childElement, classLoader));
103104
} catch (RuntimeException e) {
104-
readerContext.error(e.getMessage(), readerContext.extractSource(element), e.getCause());
105+
readerContext.error("Failed creating type filter: " + e.getMessage(), readerContext.extractSource(element),
106+
e.getCause());
105107
}
106108
}
107109

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Basic support for creating custom Spring namespaces and JavaConfig.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.config;

0 commit comments

Comments
 (0)