Skip to content

Commit 0dd856c

Browse files
committed
Migrate to JSpecify annotations for nullability constraints.
Closes #1549
1 parent ec59c45 commit 0dd856c

File tree

362 files changed

+1370
-1085
lines changed

Some content is hidden

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

362 files changed

+1370
-1085
lines changed

spring-data-cassandra/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@
227227
<artifactId>kotlinx-coroutines-reactor</artifactId>
228228
<optional>true</optional>
229229
</dependency>
230+
<dependency>
231+
<groupId>org.jspecify</groupId>
232+
<artifactId>jspecify</artifactId>
233+
<version>1.0.0</version>
234+
</dependency>
230235

231236
<dependency>
232237
<groupId>io.mockk</groupId>

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraAuthenticationException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public class CassandraAuthenticationException extends PermissionDeniedDataAccessException {
3030

31-
@Serial private static final long serialVersionUID = 8556304586797273927L;
31+
private static final @Serial long serialVersionUID = 8556304586797273927L;
3232

3333
private final EndPoint host;
3434

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraConnectionFailureException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
public class CassandraConnectionFailureException extends DataAccessResourceFailureException {
3333

34-
@Serial private static final long serialVersionUID = 6299912054261646552L;
34+
private static final @Serial long serialVersionUID = 6299912054261646552L;
3535

3636
private final Map<Node, Throwable> messagesByHost;
3737

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraInsufficientReplicasAvailableException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class CassandraInsufficientReplicasAvailableException extends TransientDataAccessException {
2828

29-
@Serial private static final long serialVersionUID = 6415130674604814905L;
29+
private static final @Serial long serialVersionUID = 6415130674604814905L;
3030

3131
private int numberRequired;
3232
private int numberAlive;

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraInternalException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class CassandraInternalException extends DataAccessException {
2828

29-
@Serial private static final long serialVersionUID = 433061676465346338L;
29+
private static final @Serial long serialVersionUID = 433061676465346338L;
3030

3131
/**
3232
* Constructor for {@link CassandraInternalException}.

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraInvalidConfigurationInQueryException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
public class CassandraInvalidConfigurationInQueryException extends InvalidDataAccessApiUsageException {
2929

30-
@Serial private static final long serialVersionUID = 4594321191806182918L;
30+
private static final @Serial long serialVersionUID = 4594321191806182918L;
3131

3232
/**
3333
* Constructor for {@link CassandraInvalidConfigurationInQueryException}.

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraInvalidQueryException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class CassandraInvalidQueryException extends InvalidDataAccessApiUsageException {
2828

29-
@Serial private static final long serialVersionUID = 4594321191806182918L;
29+
private static final @Serial long serialVersionUID = 4594321191806182918L;
3030

3131
/**
3232
* Constructor for {@link CassandraInvalidQueryException}.

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraKeyspaceExistsException.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
public class CassandraKeyspaceExistsException extends CassandraSchemaElementExistsException {
2626

27-
@Serial private static final long serialVersionUID = 6032967419751410352L;
27+
private static final @Serial long serialVersionUID = 6032967419751410352L;
2828

2929
/**
3030
* Constructor for {@link CassandraKeyspaceExistsException}.
@@ -37,6 +37,7 @@ public CassandraKeyspaceExistsException(String keyspaceName, String msg, Throwab
3737
super(keyspaceName, ElementType.KEYSPACE, msg, cause);
3838
}
3939

40+
@SuppressWarnings("NullAway")
4041
public String getKeyspaceName() {
4142
return getElementName();
4243
}

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraManagedTypes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,5 @@ public static CassandraManagedTypes empty() {
8080
public void forEach(Consumer<Class<?>> action) {
8181
delegate.forEach(action);
8282
}
83+
8384
}

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraQuerySyntaxException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class CassandraQuerySyntaxException extends InvalidDataAccessApiUsageException {
2828

29-
@Serial private static final long serialVersionUID = 4398474399882434154L;
29+
private static final @Serial long serialVersionUID = 4398474399882434154L;
3030

3131
/**
3232
* Constructor for {@link CassandraQuerySyntaxException}.

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraReadTimeoutException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
public class CassandraReadTimeoutException extends QueryTimeoutException {
2929

30-
@Serial private static final long serialVersionUID = -787022307935203387L;
30+
private static final @Serial long serialVersionUID = -787022307935203387L;
3131

3232
private final boolean wasDataPresent;
3333

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraSchemaElementExistsException.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import java.io.Serial;
1919

20+
import org.jspecify.annotations.Nullable;
2021
import org.springframework.dao.NonTransientDataAccessException;
21-
import org.springframework.lang.Nullable;
2222

2323
/**
2424
* Spring data access exception for when Cassandra schema element being created already exists.
@@ -28,15 +28,15 @@
2828
*/
2929
public class CassandraSchemaElementExistsException extends NonTransientDataAccessException {
3030

31-
@Serial private static final long serialVersionUID = 7798361273692300162L;
31+
private static final @Serial long serialVersionUID = 7798361273692300162L;
3232

3333
@Deprecated
3434
public enum ElementType {
3535
KEYSPACE, TABLE, COLUMN, INDEX
3636
}
3737

38-
private String elementName;
39-
private ElementType elementType;
38+
private @Nullable String elementName;
39+
private @Nullable ElementType elementType;
4040

4141
/**
4242
* Constructor for {@link CassandraSchemaElementExistsException}.
@@ -65,14 +65,13 @@ public CassandraSchemaElementExistsException(String msg, Throwable cause) {
6565
}
6666

6767
@Deprecated
68-
@Nullable
69-
public String getElementName() {
68+
public @Nullable String getElementName() {
7069
return elementName;
7170
}
7271

7372
@Deprecated
74-
@Nullable
75-
public ElementType getElementType() {
73+
public @Nullable ElementType getElementType() {
7674
return elementType;
7775
}
76+
7877
}

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraTableExistsException.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
public class CassandraTableExistsException extends CassandraSchemaElementExistsException {
2626

27-
@Serial private static final long serialVersionUID = 6032967419751410352L;
27+
private static final @Serial long serialVersionUID = 6032967419751410352L;
2828

2929
/**
3030
* Constructor for {@link CassandraTableExistsException}.
@@ -37,6 +37,7 @@ public CassandraTableExistsException(String tableName, String msg, Throwable cau
3737
super(tableName, ElementType.TABLE, msg, cause);
3838
}
3939

40+
@SuppressWarnings("NullAway")
4041
public String getTableName() {
4142
return getElementName();
4243
}

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraTraceRetrievalException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class CassandraTraceRetrievalException extends TransientDataAccessException {
2828

29-
@Serial private static final long serialVersionUID = -3163557220324700239L;
29+
private static final @Serial long serialVersionUID = -3163557220324700239L;
3030

3131
/**
3232
* Constructor for {@link CassandraTraceRetrievalException}.

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraTruncateException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class CassandraTruncateException extends TransientDataAccessException {
2828

29-
@Serial private static final long serialVersionUID = 5730642491362430311L;
29+
private static final @Serial long serialVersionUID = 5730642491362430311L;
3030

3131
/**
3232
* Constructor for {@link CassandraTruncateException}.

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraTypeMismatchException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class CassandraTypeMismatchException extends TypeMismatchDataAccessException {
2828

29-
@Serial private static final long serialVersionUID = -7420058975444905629L;
29+
private static final @Serial long serialVersionUID = -7420058975444905629L;
3030

3131
/**
3232
* Constructor for {@link CassandraTypeMismatchException}.

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraUnauthorizedException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*/
2727
public class CassandraUnauthorizedException extends PermissionDeniedDataAccessException {
2828

29-
@Serial private static final long serialVersionUID = 4618185356687726647L;
29+
private static final @Serial long serialVersionUID = 4618185356687726647L;
3030

3131
/**
3232
* Constructor for {@link CassandraUnauthorizedException}.

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraUncategorizedException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
public class CassandraUncategorizedException extends UncategorizedDataAccessException {
2929

30-
@Serial private static final long serialVersionUID = 1029525121238025444L;
30+
private static final @Serial long serialVersionUID = 1029525121238025444L;
3131

3232
/**
3333
* Constructor for {@link CassandraUncategorizedException}.

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/CassandraWriteTimeoutException.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
import java.io.Serial;
1919

20+
import org.jspecify.annotations.Nullable;
2021
import org.springframework.dao.QueryTimeoutException;
21-
import org.springframework.lang.Nullable;
2222

2323
/**
2424
* Spring data access exception for a Cassandra write timeout.
@@ -28,7 +28,7 @@
2828
*/
2929
public class CassandraWriteTimeoutException extends QueryTimeoutException {
3030

31-
@Serial private static final long serialVersionUID = -4374826375213670718L;
31+
private static final @Serial long serialVersionUID = -4374826375213670718L;
3232

3333
private @Nullable String writeType;
3434

@@ -45,8 +45,7 @@ public CassandraWriteTimeoutException(@Nullable String writeType, String msg, Th
4545
this.writeType = writeType;
4646
}
4747

48-
@Nullable
49-
public String getWriteType() {
48+
public @Nullable String getWriteType() {
5049
return writeType;
5150
}
5251
}

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/aot/CassandraManagedTypesBeanRegistrationAotProcessor.java

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

18+
import org.jspecify.annotations.Nullable;
1819
import org.springframework.data.aot.ManagedTypesBeanRegistrationAotProcessor;
1920
import org.springframework.data.cassandra.CassandraManagedTypes;
20-
import org.springframework.lang.Nullable;
2121
import org.springframework.util.ClassUtils;
2222

2323
/**

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/aot/CassandraRuntimeHints.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Arrays;
1919
import java.util.List;
2020

21+
import org.jspecify.annotations.Nullable;
2122
import org.springframework.aop.SpringProxy;
2223
import org.springframework.aop.framework.Advised;
2324
import org.springframework.aot.hint.MemberCategory;
@@ -32,7 +33,6 @@
3233
import org.springframework.data.cassandra.repository.support.SimpleCassandraRepository;
3334
import org.springframework.data.cassandra.repository.support.SimpleReactiveCassandraRepository;
3435
import org.springframework.data.util.ReactiveWrappers;
35-
import org.springframework.lang.Nullable;
3636
import org.springframework.util.ClassUtils;
3737

3838
import com.datastax.oss.driver.api.core.CqlSession;
@@ -106,4 +106,5 @@ public void registerHints(org.springframework.aot.hint.RuntimeHints hints, @Null
106106
}
107107
}
108108
}
109+
109110
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
/**
22
* Ahead of Time processing utilities for Spring Data Cassandra.
33
*/
4-
@NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.cassandra.aot;
6-
7-
import org.springframework.lang.NonNullApi;

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractCassandraConfiguration.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Optional;
2020
import java.util.Set;
2121

22+
import org.jspecify.annotations.Nullable;
2223
import org.springframework.beans.factory.BeanClassLoaderAware;
2324
import org.springframework.context.annotation.Bean;
2425
import org.springframework.context.annotation.Configuration;
@@ -38,7 +39,6 @@
3839
import org.springframework.data.cassandra.core.mapping.UserTypeResolver;
3940
import org.springframework.data.convert.CustomConversions;
4041
import org.springframework.data.mapping.context.MappingContext;
41-
import org.springframework.lang.Nullable;
4242

4343
import com.datastax.oss.driver.api.core.CqlIdentifier;
4444
import com.datastax.oss.driver.api.core.CqlSession;
@@ -255,8 +255,7 @@ public SchemaAction getSchemaAction() {
255255
* @return the {@link KeyspacePopulator} or {@code null} if none configured.
256256
* @see org.springframework.data.cassandra.core.cql.session.init.ResourceKeyspacePopulator
257257
*/
258-
@Nullable
259-
protected KeyspacePopulator keyspaceCleaner() {
258+
protected @Nullable KeyspacePopulator keyspaceCleaner() {
260259
return null;
261260
}
262261

@@ -266,8 +265,7 @@ protected KeyspacePopulator keyspaceCleaner() {
266265
* @return the {@link KeyspacePopulator} or {@code null} if none configured.
267266
* @see org.springframework.data.cassandra.core.cql.session.init.ResourceKeyspacePopulator
268267
*/
269-
@Nullable
270-
protected KeyspacePopulator keyspacePopulator() {
268+
protected @Nullable KeyspacePopulator keyspacePopulator() {
271269
return null;
272270
}
273271

@@ -293,4 +291,5 @@ protected ByteArrayResource scriptOf(String content) {
293291
protected UserTypeResolver userTypeResolver(CqlSession cqlSession) {
294292
return new SimpleUserTypeResolver(cqlSession, CqlIdentifier.fromCql(getKeyspaceName()));
295293
}
294+
296295
}

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/config/AbstractReactiveCassandraConfiguration.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.cassandra.config;
1717

18+
import org.jspecify.annotations.Nullable;
1819
import org.springframework.beans.BeansException;
1920
import org.springframework.beans.factory.BeanFactory;
2021
import org.springframework.context.annotation.Bean;
@@ -27,7 +28,6 @@
2728
import org.springframework.data.cassandra.core.cql.ReactiveCqlTemplate;
2829
import org.springframework.data.cassandra.core.cql.session.DefaultBridgedReactiveSession;
2930
import org.springframework.data.cassandra.core.cql.session.DefaultReactiveSessionFactory;
30-
import org.springframework.lang.Nullable;
3131

3232
/**
3333
* Extension to {@link AbstractCassandraConfiguration} providing Spring Data Cassandra configuration for Spring Data's
@@ -63,7 +63,7 @@ public ReactiveSession reactiveCassandraSession() {
6363
*/
6464
@Bean
6565
public ReactiveSessionFactory reactiveCassandraSessionFactory() {
66-
return new DefaultReactiveSessionFactory(beanFactory.getBean(ReactiveSession.class));
66+
return new DefaultReactiveSessionFactory(getBean(ReactiveSession.class));
6767
}
6868

6969
/**
@@ -75,8 +75,7 @@ public ReactiveSessionFactory reactiveCassandraSessionFactory() {
7575
*/
7676
@Bean
7777
public ReactiveCassandraTemplate reactiveCassandraTemplate() {
78-
return new ReactiveCassandraTemplate(beanFactory.getBean(ReactiveSessionFactory.class),
79-
beanFactory.getBean(CassandraConverter.class));
78+
return new ReactiveCassandraTemplate(getBean(ReactiveSessionFactory.class), getBean(CassandraConverter.class));
8079
}
8180

8281
/**
@@ -87,12 +86,22 @@ public ReactiveCassandraTemplate reactiveCassandraTemplate() {
8786
*/
8887
@Bean
8988
public ReactiveCqlTemplate reactiveCqlTemplate() {
90-
return new ReactiveCqlTemplate(beanFactory.getBean(ReactiveSessionFactory.class));
89+
return new ReactiveCqlTemplate(getBean(ReactiveSessionFactory.class));
9190
}
9291

9392
@Override
9493
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
9594
this.beanFactory = beanFactory;
9695
super.setBeanFactory(beanFactory);
9796
}
97+
98+
private <T> T getBean(Class<T> requiredType) {
99+
100+
if (beanFactory == null) {
101+
throw new IllegalStateException("BeanFactory must not be null");
102+
}
103+
104+
return beanFactory.getBean(requiredType);
105+
}
106+
98107
}

0 commit comments

Comments
 (0)