Skip to content

Commit fed5989

Browse files
committed
Migrate to JSpecify annotations for nullability constraints.
Closes #528
1 parent a034cd1 commit fed5989

36 files changed

+89
-53
lines changed

pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@
9595
<version>${cdi}</version>
9696
<optional>true</optional>
9797
</dependency>
98+
<dependency>
99+
<groupId>org.jspecify</groupId>
100+
<artifactId>jspecify</artifactId>
101+
<version>1.0.0</version>
102+
</dependency>
98103

99104
<dependency>
100105
<groupId>jakarta.annotation</groupId>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/**
22
* XML configuration support for Spring Data LDAP repositories.
33
*/
4-
@NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.ldap.config;
6-
7-
import org.springframework.lang.NonNullApi;

src/main/java/org/springframework/data/ldap/core/mapping/BasicLdapPersistentEntity.java

+1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ public class BasicLdapPersistentEntity<T> extends BasicPersistentEntity<T, LdapP
3535
public BasicLdapPersistentEntity(TypeInformation<T> information) {
3636
super(information);
3737
}
38+
3839
}

src/main/java/org/springframework/data/ldap/core/mapping/LdapMappingContext.java

+1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ protected LdapPersistentProperty createPersistentProperty(Property property, Bas
4545
SimpleTypeHolder simpleTypeHolder) {
4646
return new LdapPersistentProperty(property, owner, simpleTypeHolder);
4747
}
48+
4849
}

src/main/java/org/springframework/data/ldap/core/mapping/LdapPersistentProperty.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ public LdapPersistentProperty(Property property, PersistentEntity<?, LdapPersist
4848

4949
@Override
5050
protected Association<LdapPersistentProperty> createAssociation() {
51-
return null;
51+
throw new UnsupportedOperationException("LDAP does not support associations");
5252
}
5353

5454
@Override
5555
public boolean isIdProperty() {
5656
return isId.get();
5757
}
58+
5859
}

src/main/java/org/springframework/data/ldap/core/mapping/LdapSimpleTypes.java

+1
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ public abstract class LdapSimpleTypes {
4444
public static final SimpleTypeHolder HOLDER = new SimpleTypeHolder(VAULT_SIMPLE_TYPES, true);
4545

4646
private LdapSimpleTypes() {}
47+
4748
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
22
* Infrastructure for the LDAP object mapping subsystem.
33
*/
4-
@org.springframework.lang.NonNullApi
5-
@org.springframework.lang.NonNullFields
4+
@org.jspecify.annotations.NullMarked
65
package org.springframework.data.ldap.core.mapping;

src/main/java/org/springframework/data/ldap/repository/LdapEncoder.java

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class NameEncoder implements LdapEncoder {
4949
public String encode(String value) {
5050
return org.springframework.ldap.support.LdapEncoder.nameEncode(value);
5151
}
52+
5253
}
5354

5455
/**
@@ -79,6 +80,7 @@ public String encode(String value) {
7980

8081
return buff.toString();
8182
}
83+
8284
}
8385

8486
}

src/main/java/org/springframework/data/ldap/repository/LdapRepository.java

+1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,5 @@ public interface LdapRepository<T> extends ListCrudRepository<T, Name> {
4848
* @return the entries matching the query.
4949
*/
5050
List<T> findAll(LdapQuery ldapQuery);
51+
5152
}

src/main/java/org/springframework/data/ldap/repository/Query.java

+1
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@
7575
* @return the count limit.
7676
*/
7777
int countLimit() default 0;
78+
7879
}

src/main/java/org/springframework/data/ldap/repository/cdi/LdapRepositoryBean.java

+1
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,5 @@ protected T create(CreationalContext<T> creationalContext, Class<T> repositoryTy
7070
public Class<? extends Annotation> getScope() {
7171
return operations.getScope();
7272
}
73+
7374
}

src/main/java/org/springframework/data/ldap/repository/cdi/LdapRepositoryExtension.java

+1
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,5 @@ private <T> CdiRepositoryBean<T> createRepositoryBean(Class<T> repositoryType, S
115115
return new LdapRepositoryBean<>(LdapOperations, qualifiers, repositoryType, beanManager,
116116
Optional.of(getCustomImplementationDetector()));
117117
}
118+
118119
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* CDI support for LDAP specific repository implementation.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.ldap.repository.cdi;

src/main/java/org/springframework/data/ldap/repository/config/LdapRepositoriesRegistrar.java

+1
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ protected Class<? extends Annotation> getAnnotation() {
3636
protected RepositoryConfigurationExtension getExtension() {
3737
return new LdapRepositoryConfigurationExtension();
3838
}
39+
3940
}

src/main/java/org/springframework/data/ldap/repository/config/LdapRepositoryConfigurationExtension.java

+1
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,5 @@ public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConf
112112
protected boolean useRepositoryConfiguration(RepositoryMetadata metadata) {
113113
return !metadata.isReactiveRepository();
114114
}
115+
115116
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/**
22
* Support infrastructure for the configuration of LDAP specific repositories.
33
*/
4-
@NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.ldap.repository.config;
6-
7-
import org.springframework.lang.NonNullApi;
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* LDAP specific repository implementation.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.ldap.repository;

src/main/java/org/springframework/data/ldap/repository/query/AbstractLdapRepositoryQuery.java

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

1818
import static org.springframework.data.ldap.repository.query.LdapQueryExecution.*;
1919

20+
import org.jspecify.annotations.Nullable;
21+
2022
import org.springframework.core.convert.converter.Converter;
2123
import org.springframework.data.ldap.repository.Query;
2224
import org.springframework.data.mapping.PersistentEntity;
@@ -71,7 +73,7 @@ public AbstractLdapRepositoryQuery(LdapQueryMethod queryMethod, Class<?> entityT
7173

7274
@Override
7375
@SuppressWarnings("ConstantConditions")
74-
public final Object execute(Object[] parameters) {
76+
public final @Nullable Object execute(Object[] parameters) {
7577

7678
LdapParametersParameterAccessor parameterAccessor = new LdapParametersParameterAccessor(queryMethod, parameters);
7779
LdapQuery query = createQuery(parameterAccessor);
@@ -117,4 +119,5 @@ protected Class<?> getEntityClass() {
117119
public final QueryMethod getQueryMethod() {
118120
return queryMethod;
119121
}
122+
120123
}

src/main/java/org/springframework/data/ldap/repository/query/LdapParameterAccessor.java

+1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ public interface LdapParameterAccessor extends ParameterAccessor {
3131
* @return
3232
*/
3333
Object[] getBindableParameterValues();
34+
3435
}

src/main/java/org/springframework/data/ldap/repository/query/LdapParameters.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import java.lang.reflect.Method;
1919
import java.util.List;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.beans.BeanUtils;
2224
import org.springframework.core.MethodParameter;
2325
import org.springframework.data.geo.Distance;
@@ -27,7 +29,6 @@
2729
import org.springframework.data.repository.query.Parameters;
2830
import org.springframework.data.repository.query.ParametersSource;
2931
import org.springframework.data.util.TypeInformation;
30-
import org.springframework.lang.Nullable;
3132

3233
/**
3334
* Custom extension of {@link Parameters} discovering additional

src/main/java/org/springframework/data/ldap/repository/query/LdapQueryCreator.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616
package org.springframework.data.ldap.repository.query;
1717

18-
import static org.springframework.ldap.query.LdapQueryBuilder.*;
19-
2018
import java.util.Iterator;
2119
import java.util.List;
2220

21+
import org.jspecify.annotations.Nullable;
22+
2323
import org.springframework.core.annotation.AnnotatedElementUtils;
2424
import org.springframework.data.domain.Sort;
2525
import org.springframework.data.mapping.PropertyPath;
@@ -73,7 +73,7 @@ protected ContainerCriteria create(Part part, Iterator<Object> iterator) {
7373

7474
Entry entry = AnnotatedElementUtils.findMergedAnnotation(entityType, Entry.class);
7575

76-
LdapQueryBuilder query = query();
76+
LdapQueryBuilder query = LdapQueryBuilder.query();
7777

7878
if (entry != null) {
7979
query = query.base(entry.base());
@@ -148,7 +148,8 @@ protected ContainerCriteria or(ContainerCriteria base, ContainerCriteria criteri
148148
}
149149

150150
@Override
151-
protected LdapQuery complete(ContainerCriteria criteria, Sort sort) {
152-
return criteria;
151+
protected LdapQuery complete(@Nullable ContainerCriteria criteria, Sort sort) {
152+
return criteria == null ? LdapQueryBuilder.query() : criteria;
153153
}
154+
154155
}

src/main/java/org/springframework/data/ldap/repository/query/LdapQueryExecution.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.springframework.data.ldap.repository.query;
1717

18+
import org.jspecify.annotations.Nullable;
19+
1820
import org.springframework.core.convert.converter.Converter;
1921
import org.springframework.dao.EmptyResultDataAccessException;
2022
import org.springframework.data.convert.DtoInstantiatingConverter;
@@ -39,6 +41,7 @@
3941
@FunctionalInterface
4042
interface LdapQueryExecution {
4143

44+
@Nullable
4245
Object execute(LdapQuery query);
4346

4447
/**
@@ -57,13 +60,14 @@ final class FindOneExecution implements LdapQueryExecution {
5760
}
5861

5962
@Override
60-
public Object execute(LdapQuery query) {
63+
public @Nullable Object execute(LdapQuery query) {
6164
try {
6265
return operations.findOne(query, entityType);
6366
} catch (EmptyResultDataAccessException e) {
6467
return null;
6568
}
6669
}
70+
6771
}
6872

6973
/**
@@ -85,6 +89,7 @@ final class CollectionExecution implements LdapQueryExecution {
8589
public Object execute(LdapQuery query) {
8690
return operations.find(query, entityType);
8791
}
92+
8893
}
8994

9095
/**
@@ -108,6 +113,7 @@ final class StreamExecution implements LdapQueryExecution {
108113
public Object execute(LdapQuery query) {
109114
return operations.find(query, entityType).stream().map(resultProcessing::convert);
110115
}
116+
111117
}
112118

113119
/**
@@ -124,9 +130,12 @@ public ResultProcessingExecution(LdapQueryExecution delegate, Converter<Object,
124130
}
125131

126132
@Override
127-
public Object execute(LdapQuery query) {
128-
return converter.convert(delegate.execute(query));
133+
public @Nullable Object execute(LdapQuery query) {
134+
135+
Object result = delegate.execute(query);
136+
return result != null ? converter.convert(result) : null;
129137
}
138+
130139
}
131140

132141
/**
@@ -149,7 +158,7 @@ public ResultProcessingConverter(ResultProcessor processor,
149158
}
150159

151160
@Override
152-
public Object convert(Object source) {
161+
public @Nullable Object convert(@Nullable Object source) {
153162

154163
ReturnedType returnedType = processor.getReturnedType();
155164

@@ -165,5 +174,7 @@ public Object convert(Object source) {
165174

166175
return processor.processResult(source, converter);
167176
}
177+
168178
}
179+
169180
}

src/main/java/org/springframework/data/ldap/repository/query/LdapQueryMethod.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717

1818
import java.lang.reflect.Method;
1919

20+
import org.jspecify.annotations.Nullable;
21+
2022
import org.springframework.core.annotation.AnnotationUtils;
2123
import org.springframework.data.ldap.repository.Query;
2224
import org.springframework.data.projection.ProjectionFactory;
2325
import org.springframework.data.repository.core.RepositoryMetadata;
2426
import org.springframework.data.repository.query.QueryMethod;
25-
import org.springframework.lang.Nullable;
2627

2728
/**
2829
* QueryMethod for Ldap Queries.

src/main/java/org/springframework/data/ldap/repository/query/PartTreeLdapRepositoryQuery.java

+1
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,5 @@ protected LdapQuery createQuery(LdapParameterAccessor parameters) {
7474
getEntityClass(), objectDirectoryMapper, parameters, inputProperties);
7575
return queryCreator.createQuery();
7676
}
77+
7778
}

src/main/java/org/springframework/data/ldap/repository/query/StringBasedQuery.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
import java.util.regex.Matcher;
2828
import java.util.regex.Pattern;
2929

30+
import org.jspecify.annotations.Nullable;
31+
3032
import org.springframework.data.expression.ValueExpression;
3133
import org.springframework.data.expression.ValueExpressionParser;
3234
import org.springframework.data.repository.query.Parameter;
3335
import org.springframework.data.repository.query.ParameterAccessor;
3436
import org.springframework.data.repository.query.Parameters;
3537
import org.springframework.data.repository.query.ValueExpressionDelegate;
3638
import org.springframework.data.spel.ExpressionDependencies;
37-
import org.springframework.lang.Nullable;
3839
import org.springframework.ldap.support.LdapEncoder;
3940
import org.springframework.util.Assert;
4041
import org.springframework.util.StringUtils;
@@ -245,6 +246,7 @@ private static Matcher findNextBindingOrExpression(String input, int startPositi
245246

246247
return (matcherMap.isEmpty() ? null : matcherMap.values().iterator().next());
247248
}
249+
248250
}
249251

250252
/**
@@ -288,6 +290,7 @@ public static String bind(String input, List<Object> parameters) {
288290

289291
return result.append(input.subSequence(currentPosition, input.length())).toString();
290292
}
293+
291294
}
292295

293296
/**
@@ -349,8 +352,7 @@ public List<Object> getBindingValues() {
349352
* @param binding must not be {@literal null}.
350353
* @return the value used for the given {@link ParameterBinding}.
351354
*/
352-
@Nullable
353-
private Object getParameterValueForBinding(ParameterBinding binding) {
355+
private @Nullable Object getParameterValueForBinding(ParameterBinding binding) {
354356

355357
if (binding.isExpression()) {
356358
return evaluator.apply(binding.getRequiredExpression());
@@ -439,6 +441,9 @@ String getRequiredParameterName() {
439441

440442
return parameterName;
441443
}
444+
442445
}
446+
443447
}
448+
444449
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/**
22
* Query derivation mechanism for LDAP specific repositories.
33
*/
4-
@NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.ldap.repository.query;
6-
7-
import org.springframework.lang.NonNullApi;

src/main/java/org/springframework/data/ldap/repository/support/DefaultLdapAnnotationProcessorConfiguration.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
import javax.annotation.processing.RoundEnvironment;
2323
import javax.lang.model.element.VariableElement;
2424

25-
import org.springframework.lang.Nullable;
25+
import org.jspecify.annotations.Nullable;
26+
2627
import org.springframework.ldap.odm.annotations.Id;
2728

2829
import com.querydsl.apt.DefaultConfiguration;
@@ -55,4 +56,5 @@ public boolean isBlockedField(VariableElement field) {
5556
public boolean isValidField(VariableElement field) {
5657
return super.isValidField(field) && field.getAnnotation(Id.class) == null;
5758
}
59+
5860
}

0 commit comments

Comments
 (0)