Skip to content

Commit 12bdaf9

Browse files
committed
Migrate to JSpecify annotations for nullability constraints.
Closes #2450
1 parent 1bd04b3 commit 12bdaf9

File tree

144 files changed

+824
-441
lines changed

Some content is hidden

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

144 files changed

+824
-441
lines changed

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/AggregateReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.net.URI;
1919
import java.util.function.Function;
2020

21-
import org.springframework.lang.Nullable;
21+
import org.jspecify.annotations.Nullable;
2222
import org.springframework.web.util.UriComponents;
2323

2424
/**

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/AssociationAggregateReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.jmolecules.ddd.types.AggregateRoot;
2121
import org.jmolecules.ddd.types.Association;
2222
import org.jmolecules.ddd.types.Identifier;
23-
import org.springframework.lang.Nullable;
23+
import org.jspecify.annotations.Nullable;
2424
import org.springframework.web.util.UriComponents;
2525

2626
/**

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/Path.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import java.util.regex.Pattern;
1919

20-
import org.springframework.lang.Nullable;
20+
import org.jspecify.annotations.Nullable;
2121
import org.springframework.util.StringUtils;
2222

2323
/**

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/RepositoryConstraintViolationException.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package org.springframework.data.rest.core;
22

3+
import java.io.Serial;
4+
35
import org.springframework.dao.DataIntegrityViolationException;
46
import org.springframework.validation.Errors;
57

68
/**
79
* Exception that is thrown when a Spring {@link org.springframework.validation.Validator} throws an error.
8-
*
10+
*
911
* @author Jon Brisbin
1012
*/
1113
public class RepositoryConstraintViolationException extends DataIntegrityViolationException {
1214

13-
private static final long serialVersionUID = -4789377071564956366L;
15+
private static final @Serial long serialVersionUID = -4789377071564956366L;
1416

1517
private final Errors errors;
1618

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/ResolvingAggregateReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.net.URI;
1919
import java.util.function.Function;
2020

21-
import org.springframework.lang.Nullable;
21+
import org.jspecify.annotations.Nullable;
2222
import org.springframework.util.Assert;
2323
import org.springframework.web.util.UriComponents;
2424
import org.springframework.web.util.UriComponentsBuilder;

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/UriToEntityConverter.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@
2020
import java.util.Set;
2121
import java.util.function.Supplier;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.core.convert.ConversionFailedException;
2426
import org.springframework.core.convert.ConversionService;
2527
import org.springframework.core.convert.TypeDescriptor;
2628
import org.springframework.core.convert.converter.GenericConverter;
29+
import org.springframework.data.mapping.PersistentEntity;
2730
import org.springframework.data.mapping.context.PersistentEntities;
2831
import org.springframework.data.repository.support.Repositories;
2932
import org.springframework.data.repository.support.RepositoryInvokerFactory;
3033
import org.springframework.data.util.ClassUtils;
3134
import org.springframework.data.util.TypeInformation;
32-
import org.springframework.lang.NonNull;
33-
import org.springframework.lang.Nullable;
3435
import org.springframework.util.Assert;
3536

3637
/**
@@ -41,7 +42,8 @@
4142
*/
4243
public class UriToEntityConverter implements GenericConverter {
4344

44-
private static final Class<?> ASSOCIATION_TYPE = ClassUtils.loadIfPresent("org.jmolecules.ddd.types.Association",
45+
private static final @Nullable Class<?> ASSOCIATION_TYPE = ClassUtils
46+
.loadIfPresent("org.jmolecules.ddd.types.Association",
4547
UriToEntityConverter.class.getClassLoader());
4648

4749
private final PersistentEntities entities;
@@ -74,7 +76,7 @@ public UriToEntityConverter(PersistentEntities entities, RepositoryInvokerFactor
7476
var rawType = domainType.getType();
7577
var entity = entities.getPersistentEntity(rawType);
7678

77-
entity.filter(it -> it.hasIdProperty()).ifPresent(it -> {
79+
entity.filter(PersistentEntity::hasIdProperty).ifPresent(it -> {
7880
convertiblePairs.add(new ConvertiblePair(URI.class, domainType.getType()));
7981
registerIdentifierType(it.getRequiredIdProperty().getType());
8082
});
@@ -95,7 +97,6 @@ private void registerIdentifierType(Class<?> type) {
9597
identifierTypes.add(type);
9698
}
9799

98-
@NonNull
99100
@Override
100101
public Set<ConvertiblePair> getConvertibleTypes() {
101102
return convertiblePairs;

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/ValidationErrors.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
*/
1616
package org.springframework.data.rest.core;
1717

18+
import java.io.Serial;
1819
import java.util.Arrays;
1920
import java.util.Collection;
2021
import java.util.Iterator;
2122
import java.util.Optional;
2223

24+
import org.jspecify.annotations.Nullable;
25+
2326
import org.springframework.beans.BeansException;
2427
import org.springframework.beans.ConfigurablePropertyAccessor;
2528
import org.springframework.beans.DirectFieldAccessor;
@@ -29,7 +32,6 @@
2932
import org.springframework.data.mapping.PersistentEntity;
3033
import org.springframework.data.mapping.PersistentProperty;
3134
import org.springframework.data.mapping.context.PersistentEntities;
32-
import org.springframework.lang.Nullable;
3335
import org.springframework.util.Assert;
3436
import org.springframework.validation.AbstractPropertyBindingResult;
3537

@@ -44,7 +46,7 @@
4446
*/
4547
public class ValidationErrors extends AbstractPropertyBindingResult {
4648

47-
private static final long serialVersionUID = 8141826537389141361L;
49+
private static final @Serial long serialVersionUID = 8141826537389141361L;
4850

4951
private final Object source;
5052
private final PersistentEntities entities;
@@ -72,6 +74,7 @@ public ConfigurablePropertyAccessor getPropertyAccessor() {
7274
return new DirectFieldAccessor(getTarget()) {
7375

7476
@Override
77+
@Nullable
7578
public Object getPropertyValue(String propertyName) throws BeansException {
7679

7780
Collection<String> segments = Arrays.asList(propertyName.split("\\."));
@@ -82,7 +85,7 @@ public Object getPropertyValue(String propertyName) throws BeansException {
8285

8386
value = lookupValueOn(value, iterator.next());
8487

85-
} while (iterator.hasNext());
88+
} while (value != null && iterator.hasNext());
8689

8790
return value;
8891
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@org.jspecify.annotations.NullMarked
2+
package org.springframework.data.rest.core.annotation;

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/EntityLookupConfiguration.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.Objects;
2121
import java.util.Optional;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.core.convert.converter.Converter;
2426
import org.springframework.data.repository.Repository;
2527
import org.springframework.data.repository.core.RepositoryInformation;
@@ -29,7 +31,6 @@
2931
import org.springframework.data.rest.core.support.EntityLookup;
3032
import org.springframework.data.util.MethodInvocationRecorder;
3133
import org.springframework.data.util.StreamUtils;
32-
import org.springframework.lang.Nullable;
3334
import org.springframework.util.Assert;
3435

3536
/**
@@ -41,7 +42,7 @@
4142
*/
4243
class EntityLookupConfiguration implements EntityLookupRegistrar {
4344

44-
private final List<LookupInformation<Object, Object, Repository<? extends Object, ?>>> lookupInformation = new ArrayList<>();
45+
private final List<LookupInformation<Object, Object, Repository<?, ?>>> lookupInformation = new ArrayList<>();
4546
private final List<Class<?>> lookupTypes = new ArrayList<>();
4647

4748
@Override
@@ -84,7 +85,7 @@ private class MappingBuilder<T, ID, R extends Repository<T, ?>>
8485
implements LookupRegistrar<T, ID, R>, IdMappingRegistrar<T, R> {
8586

8687
private final Class<R> repositoryType;
87-
private Converter<T, ID> idMapping;
88+
private @Nullable Converter<T, ID> idMapping;
8889

8990
/**
9091
* Creates a new {@link MappingBuilder} for the given repository type.
@@ -114,8 +115,10 @@ private MappingBuilder(Class<R> repositoryType, Converter<T, ID> mapping) {
114115
@SuppressWarnings("unchecked")
115116
public EntityLookupRegistrar withLookup(Lookup<R, ID> lookup) {
116117

118+
Assert.notNull(idMapping, "IdMapping must not be null");
119+
117120
EntityLookupConfiguration.this.lookupInformation
118-
.add((LookupInformation<Object, Object, Repository<? extends Object, ?>>) new LookupInformation<T, ID, R>(
121+
.add((LookupInformation<Object, Object, Repository<?, ?>>) new LookupInformation<T, ID, R>(
119122
repositoryType, idMapping, lookup));
120123

121124
return EntityLookupConfiguration.this;
@@ -186,7 +189,7 @@ public RepositoriesEntityLookup(Repositories repositories,
186189

187190
@Override
188191
public Object getResourceIdentifier(T entity) {
189-
return lookupInfo.getIdentifierMapping().convert(entity);
192+
return Objects.requireNonNull(lookupInfo.getIdentifierMapping().convert(entity));
190193
}
191194

192195
@Override
@@ -239,7 +242,7 @@ public Lookup<R, ID> getLookup() {
239242
}
240243

241244
@Override
242-
public boolean equals(@Nullable final java.lang.Object o) {
245+
public boolean equals(@Nullable Object o) {
243246

244247
if (o == this) {
245248
return true;

spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/MetadataConfiguration.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.Map.Entry;
2121
import java.util.regex.Pattern;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.util.Assert;
2426

2527
/**
@@ -29,8 +31,8 @@
2931
*/
3032
public class MetadataConfiguration {
3133

32-
private final Map<Class<?>, JsonSchemaFormat> schemaFormats = new HashMap<Class<?>, JsonSchemaFormat>();
33-
private final Map<Class<?>, Pattern> patterns = new HashMap<Class<?>, Pattern>();
34+
private final Map<Class<?>, JsonSchemaFormat> schemaFormats = new HashMap<>();
35+
private final Map<Class<?>, Pattern> patterns = new HashMap<>();
3436
private boolean omitUnresolvableDescriptionKeys = true;
3537
private boolean alpsEnabled = true;
3638

@@ -88,7 +90,7 @@ public void registerJsonSchemaFormat(JsonSchemaFormat format, Class<?>... types)
8890
* @param type must not be {@literal null}.
8991
* @return
9092
*/
91-
public JsonSchemaFormat getSchemaFormatFor(Class<?> type) {
93+
public @Nullable JsonSchemaFormat getSchemaFormatFor(Class<?> type) {
9294
return schemaFormats.get(type);
9395
}
9496

@@ -112,7 +114,7 @@ public void registerFormattingPatternFor(String pattern, Class<?> type) {
112114
* @param type must not be {@literal null}.
113115
* @return
114116
*/
115-
public Pattern getPatternFor(Class<?> type) {
117+
public @Nullable Pattern getPatternFor(Class<?> type) {
116118

117119
Assert.notNull(type, "Type must not be null");
118120

0 commit comments

Comments
 (0)