Browse Source

Add nullability annotations to module/spring-boot-cassandra

See gh-46587
pull/46602/head
Moritz Halbritter 8 months ago
parent
commit
5321acdccb
  1. 22
      module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/autoconfigure/CassandraAutoConfiguration.java
  2. 10
      module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/autoconfigure/CassandraConnectionDetails.java
  3. 141
      module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/autoconfigure/CassandraProperties.java
  4. 3
      module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/autoconfigure/health/package-info.java
  5. 3
      module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/autoconfigure/package-info.java
  6. 3
      module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/docker/compose/package-info.java
  7. 3
      module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/health/package-info.java
  8. 3
      module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/testcontainers/CassandraContainerConnectionDetailsFactory.java
  9. 3
      module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/testcontainers/package-info.java

22
module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/autoconfigure/CassandraAutoConfiguration.java

@ -34,6 +34,7 @@ import com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfig @@ -34,6 +34,7 @@ import com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfig
import com.datastax.oss.driver.internal.core.config.typesafe.DefaultProgrammaticDriverConfigLoaderBuilder;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -123,8 +124,9 @@ public final class CassandraAutoConfiguration { @@ -123,8 +124,9 @@ public final class CassandraAutoConfiguration {
private void configureAuthentication(CqlSessionBuilder builder, CassandraConnectionDetails connectionDetails) {
String username = connectionDetails.getUsername();
if (username != null) {
builder.withAuthCredentials(username, connectionDetails.getPassword());
String password = connectionDetails.getPassword();
if (username != null && password != null) {
builder.withAuthCredentials(username, password);
}
}
@ -260,7 +262,7 @@ public final class CassandraAutoConfiguration { @@ -260,7 +262,7 @@ public final class CassandraAutoConfiguration {
private final Map<String, String> options = new LinkedHashMap<>();
private CassandraDriverOptions add(DriverOption option, String value) {
private CassandraDriverOptions add(DriverOption option, @Nullable String value) {
String key = createKeyFor(option);
this.options.put(key, value);
return this;
@ -298,9 +300,9 @@ public final class CassandraAutoConfiguration { @@ -298,9 +300,9 @@ public final class CassandraAutoConfiguration {
private final CassandraProperties properties;
private final SslBundles sslBundles;
private final @Nullable SslBundles sslBundles;
private PropertiesCassandraConnectionDetails(CassandraProperties properties, SslBundles sslBundles) {
private PropertiesCassandraConnectionDetails(CassandraProperties properties, @Nullable SslBundles sslBundles) {
this.properties = properties;
this.sslBundles = sslBundles;
}
@ -313,22 +315,22 @@ public final class CassandraAutoConfiguration { @@ -313,22 +315,22 @@ public final class CassandraAutoConfiguration {
}
@Override
public String getUsername() {
public @Nullable String getUsername() {
return this.properties.getUsername();
}
@Override
public String getPassword() {
public @Nullable String getPassword() {
return this.properties.getPassword();
}
@Override
public String getLocalDatacenter() {
public @Nullable String getLocalDatacenter() {
return this.properties.getLocalDatacenter();
}
@Override
public SslBundle getSslBundle() {
public @Nullable SslBundle getSslBundle() {
Ssl ssl = this.properties.getSsl();
if (ssl == null || !ssl.isEnabled()) {
return null;
@ -352,7 +354,7 @@ public final class CassandraAutoConfiguration { @@ -352,7 +354,7 @@ public final class CassandraAutoConfiguration {
return new Node(contactPoint, this.properties.getPort());
}
private Integer asPort(String value) {
private @Nullable Integer asPort(String value) {
try {
int i = Integer.parseInt(value);
return (i > 0 && i < 65535) ? i : null;

10
module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/autoconfigure/CassandraConnectionDetails.java

@ -18,6 +18,8 @@ package org.springframework.boot.cassandra.autoconfigure; @@ -18,6 +18,8 @@ package org.springframework.boot.cassandra.autoconfigure;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
import org.springframework.boot.ssl.SslBundle;
@ -41,7 +43,7 @@ public interface CassandraConnectionDetails extends ConnectionDetails { @@ -41,7 +43,7 @@ public interface CassandraConnectionDetails extends ConnectionDetails {
* Login user of the server.
* @return the login user of the server or {@code null}
*/
default String getUsername() {
default @Nullable String getUsername() {
return null;
}
@ -49,7 +51,7 @@ public interface CassandraConnectionDetails extends ConnectionDetails { @@ -49,7 +51,7 @@ public interface CassandraConnectionDetails extends ConnectionDetails {
* Login password of the server.
* @return the login password of the server or {@code null}
*/
default String getPassword() {
default @Nullable String getPassword() {
return null;
}
@ -58,13 +60,13 @@ public interface CassandraConnectionDetails extends ConnectionDetails { @@ -58,13 +60,13 @@ public interface CassandraConnectionDetails extends ConnectionDetails {
* datacenter.
* @return the datacenter that is considered "local"
*/
String getLocalDatacenter();
@Nullable String getLocalDatacenter();
/**
* SSL bundle to use.
* @return the SSL bundle to use
*/
default SslBundle getSslBundle() {
default @Nullable SslBundle getSslBundle() {
return null;
}

141
module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/autoconfigure/CassandraProperties.java

@ -20,6 +20,7 @@ import java.time.Duration; @@ -20,6 +20,7 @@ import java.time.Duration;
import java.util.List;
import com.datastax.oss.driver.api.core.DefaultConsistencyLevel;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.Resource;
@ -40,23 +41,23 @@ public class CassandraProperties { @@ -40,23 +41,23 @@ public class CassandraProperties {
/**
* Location of the configuration file to use.
*/
private Resource config;
private @Nullable Resource config;
/**
* Keyspace name to use.
*/
private String keyspaceName;
private @Nullable String keyspaceName;
/**
* Name of the Cassandra session.
*/
private String sessionName;
private @Nullable String sessionName;
/**
* Cluster node addresses in the form 'host:port', or a simple 'host' to use the
* configured port.
*/
private List<String> contactPoints;
private @Nullable List<String> contactPoints;
/**
* Port to use if a contact point does not specify one.
@ -67,22 +68,22 @@ public class CassandraProperties { @@ -67,22 +68,22 @@ public class CassandraProperties {
* Datacenter that is considered "local". Contact points should be from this
* datacenter.
*/
private String localDatacenter;
private @Nullable String localDatacenter;
/**
* Login user of the server.
*/
private String username;
private @Nullable String username;
/**
* Login password of the server.
*/
private String password;
private @Nullable String password;
/**
* Compression supported by the Cassandra binary protocol.
*/
private Compression compression;
private @Nullable Compression compression;
/**
* Schema action to take at startup.
@ -114,35 +115,35 @@ public class CassandraProperties { @@ -114,35 +115,35 @@ public class CassandraProperties {
*/
private final Controlconnection controlconnection = new Controlconnection();
public Resource getConfig() {
public @Nullable Resource getConfig() {
return this.config;
}
public void setConfig(Resource config) {
public void setConfig(@Nullable Resource config) {
this.config = config;
}
public String getKeyspaceName() {
public @Nullable String getKeyspaceName() {
return this.keyspaceName;
}
public void setKeyspaceName(String keyspaceName) {
public void setKeyspaceName(@Nullable String keyspaceName) {
this.keyspaceName = keyspaceName;
}
public String getSessionName() {
public @Nullable String getSessionName() {
return this.sessionName;
}
public void setSessionName(String sessionName) {
public void setSessionName(@Nullable String sessionName) {
this.sessionName = sessionName;
}
public List<String> getContactPoints() {
public @Nullable List<String> getContactPoints() {
return this.contactPoints;
}
public void setContactPoints(List<String> contactPoints) {
public void setContactPoints(@Nullable List<String> contactPoints) {
this.contactPoints = contactPoints;
}
@ -154,35 +155,35 @@ public class CassandraProperties { @@ -154,35 +155,35 @@ public class CassandraProperties {
this.port = port;
}
public String getLocalDatacenter() {
public @Nullable String getLocalDatacenter() {
return this.localDatacenter;
}
public void setLocalDatacenter(String localDatacenter) {
public void setLocalDatacenter(@Nullable String localDatacenter) {
this.localDatacenter = localDatacenter;
}
public String getUsername() {
public @Nullable String getUsername() {
return this.username;
}
public void setUsername(String username) {
public void setUsername(@Nullable String username) {
this.username = username;
}
public String getPassword() {
public @Nullable String getPassword() {
return this.password;
}
public void setPassword(String password) {
public void setPassword(@Nullable String password) {
this.password = password;
}
public Compression getCompression() {
public @Nullable Compression getCompression() {
return this.compression;
}
public void setCompression(Compression compression) {
public void setCompression(@Nullable Compression compression) {
this.compression = compression;
}
@ -223,12 +224,12 @@ public class CassandraProperties { @@ -223,12 +224,12 @@ public class CassandraProperties {
/**
* Whether to enable SSL support.
*/
private Boolean enabled;
private @Nullable Boolean enabled;
/**
* SSL bundle name.
*/
private String bundle;
private @Nullable String bundle;
public boolean isEnabled() {
return (this.enabled != null) ? this.enabled : this.bundle != null;
@ -238,11 +239,11 @@ public class CassandraProperties { @@ -238,11 +239,11 @@ public class CassandraProperties {
this.enabled = enabled;
}
public String getBundle() {
public @Nullable String getBundle() {
return this.bundle;
}
public void setBundle(String bundle) {
public void setBundle(@Nullable String bundle) {
this.bundle = bundle;
}
@ -253,27 +254,27 @@ public class CassandraProperties { @@ -253,27 +254,27 @@ public class CassandraProperties {
/**
* Timeout to use when establishing driver connections.
*/
private Duration connectTimeout;
private @Nullable Duration connectTimeout;
/**
* Timeout to use for internal queries that run as part of the initialization
* process, just after a connection is opened.
*/
private Duration initQueryTimeout;
private @Nullable Duration initQueryTimeout;
public Duration getConnectTimeout() {
public @Nullable Duration getConnectTimeout() {
return this.connectTimeout;
}
public void setConnectTimeout(Duration connectTimeout) {
public void setConnectTimeout(@Nullable Duration connectTimeout) {
this.connectTimeout = connectTimeout;
}
public Duration getInitQueryTimeout() {
public @Nullable Duration getInitQueryTimeout() {
return this.initQueryTimeout;
}
public void setInitQueryTimeout(Duration initQueryTimeout) {
public void setInitQueryTimeout(@Nullable Duration initQueryTimeout) {
this.initQueryTimeout = initQueryTimeout;
}
@ -284,54 +285,54 @@ public class CassandraProperties { @@ -284,54 +285,54 @@ public class CassandraProperties {
/**
* How long the driver waits for a request to complete.
*/
private Duration timeout;
private @Nullable Duration timeout;
/**
* Queries consistency level.
*/
private DefaultConsistencyLevel consistency;
private @Nullable DefaultConsistencyLevel consistency;
/**
* Queries serial consistency level.
*/
private DefaultConsistencyLevel serialConsistency;
private @Nullable DefaultConsistencyLevel serialConsistency;
/**
* How many rows will be retrieved simultaneously in a single network round-trip.
*/
private Integer pageSize;
private @Nullable Integer pageSize;
private final Throttler throttler = new Throttler();
public Duration getTimeout() {
public @Nullable Duration getTimeout() {
return this.timeout;
}
public void setTimeout(Duration timeout) {
public void setTimeout(@Nullable Duration timeout) {
this.timeout = timeout;
}
public DefaultConsistencyLevel getConsistency() {
public @Nullable DefaultConsistencyLevel getConsistency() {
return this.consistency;
}
public void setConsistency(DefaultConsistencyLevel consistency) {
public void setConsistency(@Nullable DefaultConsistencyLevel consistency) {
this.consistency = consistency;
}
public DefaultConsistencyLevel getSerialConsistency() {
public @Nullable DefaultConsistencyLevel getSerialConsistency() {
return this.serialConsistency;
}
public void setSerialConsistency(DefaultConsistencyLevel serialConsistency) {
public void setSerialConsistency(@Nullable DefaultConsistencyLevel serialConsistency) {
this.serialConsistency = serialConsistency;
}
public Integer getPageSize() {
public @Nullable Integer getPageSize() {
return this.pageSize;
}
public void setPageSize(int pageSize) {
public void setPageSize(@Nullable Integer pageSize) {
this.pageSize = pageSize;
}
@ -349,27 +350,27 @@ public class CassandraProperties { @@ -349,27 +350,27 @@ public class CassandraProperties {
/**
* Idle timeout before an idle connection is removed.
*/
private Duration idleTimeout;
private @Nullable Duration idleTimeout;
/**
* Heartbeat interval after which a message is sent on an idle connection to make
* sure it's still alive.
*/
private Duration heartbeatInterval;
private @Nullable Duration heartbeatInterval;
public Duration getIdleTimeout() {
public @Nullable Duration getIdleTimeout() {
return this.idleTimeout;
}
public void setIdleTimeout(Duration idleTimeout) {
public void setIdleTimeout(@Nullable Duration idleTimeout) {
this.idleTimeout = idleTimeout;
}
public Duration getHeartbeatInterval() {
public @Nullable Duration getHeartbeatInterval() {
return this.heartbeatInterval;
}
public void setHeartbeatInterval(Duration heartbeatInterval) {
public void setHeartbeatInterval(@Nullable Duration heartbeatInterval) {
this.heartbeatInterval = heartbeatInterval;
}
@ -380,13 +381,13 @@ public class CassandraProperties { @@ -380,13 +381,13 @@ public class CassandraProperties {
/**
* Timeout to use for control queries.
*/
private Duration timeout;
private @Nullable Duration timeout;
public Duration getTimeout() {
public @Nullable Duration getTimeout() {
return this.timeout;
}
public void setTimeout(Duration timeout) {
public void setTimeout(@Nullable Duration timeout) {
this.timeout = timeout;
}
@ -397,68 +398,68 @@ public class CassandraProperties { @@ -397,68 +398,68 @@ public class CassandraProperties {
/**
* Request throttling type.
*/
private ThrottlerType type;
private @Nullable ThrottlerType type;
/**
* Maximum number of requests that can be enqueued when the throttling threshold
* is exceeded.
*/
private Integer maxQueueSize;
private @Nullable Integer maxQueueSize;
/**
* Maximum number of requests that are allowed to execute in parallel.
*/
private Integer maxConcurrentRequests;
private @Nullable Integer maxConcurrentRequests;
/**
* Maximum allowed request rate.
*/
private Integer maxRequestsPerSecond;
private @Nullable Integer maxRequestsPerSecond;
/**
* How often the throttler attempts to dequeue requests. Set this high enough that
* each attempt will process multiple entries in the queue, but not delay requests
* too much.
*/
private Duration drainInterval;
private @Nullable Duration drainInterval;
public ThrottlerType getType() {
public @Nullable ThrottlerType getType() {
return this.type;
}
public void setType(ThrottlerType type) {
public void setType(@Nullable ThrottlerType type) {
this.type = type;
}
public Integer getMaxQueueSize() {
public @Nullable Integer getMaxQueueSize() {
return this.maxQueueSize;
}
public void setMaxQueueSize(int maxQueueSize) {
public void setMaxQueueSize(@Nullable Integer maxQueueSize) {
this.maxQueueSize = maxQueueSize;
}
public Integer getMaxConcurrentRequests() {
public @Nullable Integer getMaxConcurrentRequests() {
return this.maxConcurrentRequests;
}
public void setMaxConcurrentRequests(int maxConcurrentRequests) {
public void setMaxConcurrentRequests(@Nullable Integer maxConcurrentRequests) {
this.maxConcurrentRequests = maxConcurrentRequests;
}
public Integer getMaxRequestsPerSecond() {
public @Nullable Integer getMaxRequestsPerSecond() {
return this.maxRequestsPerSecond;
}
public void setMaxRequestsPerSecond(int maxRequestsPerSecond) {
public void setMaxRequestsPerSecond(@Nullable Integer maxRequestsPerSecond) {
this.maxRequestsPerSecond = maxRequestsPerSecond;
}
public Duration getDrainInterval() {
public @Nullable Duration getDrainInterval() {
return this.drainInterval;
}
public void setDrainInterval(Duration drainInterval) {
public void setDrainInterval(@Nullable Duration drainInterval) {
this.drainInterval = drainInterval;
}

3
module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/autoconfigure/health/package-info.java

@ -17,4 +17,7 @@ @@ -17,4 +17,7 @@
/**
* Auto-configuration for Cassandra health.
*/
@NullMarked
package org.springframework.boot.cassandra.autoconfigure.health;
import org.jspecify.annotations.NullMarked;

3
module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/autoconfigure/package-info.java

@ -17,4 +17,7 @@ @@ -17,4 +17,7 @@
/**
* Auto-configuration for Cassandra.
*/
@NullMarked
package org.springframework.boot.cassandra.autoconfigure;
import org.jspecify.annotations.NullMarked;

3
module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/docker/compose/package-info.java

@ -17,4 +17,7 @@ @@ -17,4 +17,7 @@
/**
* Support for Docker Compose Cassandra service connections.
*/
@NullMarked
package org.springframework.boot.cassandra.docker.compose;
import org.jspecify.annotations.NullMarked;

3
module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/health/package-info.java

@ -17,4 +17,7 @@ @@ -17,4 +17,7 @@
/**
* Health integration for Cassandra.
*/
@NullMarked
package org.springframework.boot.cassandra.health;
import org.jspecify.annotations.NullMarked;

3
module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/testcontainers/CassandraContainerConnectionDetailsFactory.java

@ -19,6 +19,7 @@ package org.springframework.boot.cassandra.testcontainers; @@ -19,6 +19,7 @@ package org.springframework.boot.cassandra.testcontainers;
import java.net.InetSocketAddress;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.testcontainers.cassandra.CassandraContainer;
import org.springframework.boot.cassandra.autoconfigure.CassandraConnectionDetails;
@ -77,7 +78,7 @@ class CassandraContainerConnectionDetailsFactory @@ -77,7 +78,7 @@ class CassandraContainerConnectionDetailsFactory
}
@Override
public SslBundle getSslBundle() {
public @Nullable SslBundle getSslBundle() {
return super.getSslBundle();
}

3
module/spring-boot-cassandra/src/main/java/org/springframework/boot/cassandra/testcontainers/package-info.java

@ -17,4 +17,7 @@ @@ -17,4 +17,7 @@
/**
* Support for testcontainers Cassandra service connections.
*/
@NullMarked
package org.springframework.boot.cassandra.testcontainers;
import org.jspecify.annotations.NullMarked;

Loading…
Cancel
Save