Skip to content

Commit 5321acd

Browse files
committed
Add nullability annotations to module/spring-boot-cassandra
See gh-46587
1 parent fccc768 commit 5321acd

File tree

9 files changed

+106
-85
lines changed

9 files changed

+106
-85
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import com.datastax.oss.driver.internal.core.config.typesafe.DefaultProgrammaticDriverConfigLoaderBuilder;
3535
import com.typesafe.config.Config;
3636
import com.typesafe.config.ConfigFactory;
37+
import org.jspecify.annotations.Nullable;
3738

3839
import org.springframework.beans.factory.ObjectProvider;
3940
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@@ -123,8 +124,9 @@ CqlSessionBuilder cassandraSessionBuilder(DriverConfigLoader driverConfigLoader,
123124

124125
private void configureAuthentication(CqlSessionBuilder builder, CassandraConnectionDetails connectionDetails) {
125126
String username = connectionDetails.getUsername();
126-
if (username != null) {
127-
builder.withAuthCredentials(username, connectionDetails.getPassword());
127+
String password = connectionDetails.getPassword();
128+
if (username != null && password != null) {
129+
builder.withAuthCredentials(username, password);
128130
}
129131
}
130132

@@ -260,7 +262,7 @@ private static final class CassandraDriverOptions {
260262

261263
private final Map<String, String> options = new LinkedHashMap<>();
262264

263-
private CassandraDriverOptions add(DriverOption option, String value) {
265+
private CassandraDriverOptions add(DriverOption option, @Nullable String value) {
264266
String key = createKeyFor(option);
265267
this.options.put(key, value);
266268
return this;
@@ -298,9 +300,9 @@ static final class PropertiesCassandraConnectionDetails implements CassandraConn
298300

299301
private final CassandraProperties properties;
300302

301-
private final SslBundles sslBundles;
303+
private final @Nullable SslBundles sslBundles;
302304

303-
private PropertiesCassandraConnectionDetails(CassandraProperties properties, SslBundles sslBundles) {
305+
private PropertiesCassandraConnectionDetails(CassandraProperties properties, @Nullable SslBundles sslBundles) {
304306
this.properties = properties;
305307
this.sslBundles = sslBundles;
306308
}
@@ -313,22 +315,22 @@ public List<Node> getContactPoints() {
313315
}
314316

315317
@Override
316-
public String getUsername() {
318+
public @Nullable String getUsername() {
317319
return this.properties.getUsername();
318320
}
319321

320322
@Override
321-
public String getPassword() {
323+
public @Nullable String getPassword() {
322324
return this.properties.getPassword();
323325
}
324326

325327
@Override
326-
public String getLocalDatacenter() {
328+
public @Nullable String getLocalDatacenter() {
327329
return this.properties.getLocalDatacenter();
328330
}
329331

330332
@Override
331-
public SslBundle getSslBundle() {
333+
public @Nullable SslBundle getSslBundle() {
332334
Ssl ssl = this.properties.getSsl();
333335
if (ssl == null || !ssl.isEnabled()) {
334336
return null;
@@ -352,7 +354,7 @@ private Node asNode(String contactPoint) {
352354
return new Node(contactPoint, this.properties.getPort());
353355
}
354356

355-
private Integer asPort(String value) {
357+
private @Nullable Integer asPort(String value) {
356358
try {
357359
int i = Integer.parseInt(value);
358360
return (i > 0 && i < 65535) ? i : null;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.List;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
2224
import org.springframework.boot.ssl.SslBundle;
2325

@@ -41,15 +43,15 @@ public interface CassandraConnectionDetails extends ConnectionDetails {
4143
* Login user of the server.
4244
* @return the login user of the server or {@code null}
4345
*/
44-
default String getUsername() {
46+
default @Nullable String getUsername() {
4547
return null;
4648
}
4749

4850
/**
4951
* Login password of the server.
5052
* @return the login password of the server or {@code null}
5153
*/
52-
default String getPassword() {
54+
default @Nullable String getPassword() {
5355
return null;
5456
}
5557

@@ -58,13 +60,13 @@ default String getPassword() {
5860
* datacenter.
5961
* @return the datacenter that is considered "local"
6062
*/
61-
String getLocalDatacenter();
63+
@Nullable String getLocalDatacenter();
6264

6365
/**
6466
* SSL bundle to use.
6567
* @return the SSL bundle to use
6668
*/
67-
default SslBundle getSslBundle() {
69+
default @Nullable SslBundle getSslBundle() {
6870
return null;
6971
}
7072

0 commit comments

Comments
 (0)