Skip to content

Commit f9a6217

Browse files
committed
Add nullability annotations to module/spring-boot-couchbase
See gh-46587
1 parent 071f012 commit f9a6217

File tree

8 files changed

+67
-40
lines changed

8 files changed

+67
-40
lines changed

module/spring-boot-couchbase/src/main/java/org/springframework/boot/couchbase/autoconfigure/CouchbaseAutoConfiguration.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
import java.io.InputStream;
2121
import java.security.GeneralSecurityException;
2222
import java.security.KeyStore;
23+
import java.security.PrivateKey;
24+
import java.security.cert.X509Certificate;
25+
import java.util.List;
2326

2427
import javax.net.ssl.TrustManagerFactory;
2528

@@ -33,6 +36,7 @@
3336
import com.couchbase.client.java.env.ClusterEnvironment.Builder;
3437
import com.couchbase.client.java.json.JsonValueModule;
3538
import com.fasterxml.jackson.databind.ObjectMapper;
39+
import org.jspecify.annotations.Nullable;
3640

3741
import org.springframework.beans.factory.ObjectProvider;
3842
import org.springframework.boot.autoconfigure.AutoConfiguration;
@@ -115,8 +119,12 @@ Authenticator couchbaseAuthenticator(CouchbaseConnectionDetails connectionDetail
115119
if (pem.getCertificates() != null) {
116120
PemSslStoreDetails details = new PemSslStoreDetails(null, pem.getCertificates(), pem.getPrivateKey());
117121
PemSslStore store = PemSslStore.load(details);
118-
return CertificateAuthenticator.fromKey(store.privateKey(), pem.getPrivateKeyPassword(),
119-
store.certificates());
122+
Assert.state(store != null, "Unable to load key and certificates");
123+
PrivateKey key = store.privateKey();
124+
List<X509Certificate> certificates = store.certificates();
125+
Assert.state(key != null, "No key found");
126+
Assert.state(certificates != null, "No certificates found");
127+
return CertificateAuthenticator.fromKey(key, pem.getPrivateKeyPassword(), certificates);
120128
}
121129
Jks jks = this.properties.getAuthentication().getJks();
122130
if (jks.getLocation() != null) {
@@ -239,30 +247,32 @@ static final class PropertiesCouchbaseConnectionDetails implements CouchbaseConn
239247

240248
private final CouchbaseProperties properties;
241249

242-
private final SslBundles sslBundles;
250+
private final @Nullable SslBundles sslBundles;
243251

244-
PropertiesCouchbaseConnectionDetails(CouchbaseProperties properties, SslBundles sslBundles) {
252+
PropertiesCouchbaseConnectionDetails(CouchbaseProperties properties, @Nullable SslBundles sslBundles) {
245253
this.properties = properties;
246254
this.sslBundles = sslBundles;
247255
}
248256

249257
@Override
250258
public String getConnectionString() {
251-
return this.properties.getConnectionString();
259+
String connectionString = this.properties.getConnectionString();
260+
Assert.state(connectionString != null, "'connectionString' must not be null");
261+
return connectionString;
252262
}
253263

254264
@Override
255-
public String getUsername() {
265+
public @Nullable String getUsername() {
256266
return this.properties.getUsername();
257267
}
258268

259269
@Override
260-
public String getPassword() {
270+
public @Nullable String getPassword() {
261271
return this.properties.getPassword();
262272
}
263273

264274
@Override
265-
public SslBundle getSslBundle() {
275+
public @Nullable SslBundle getSslBundle() {
266276
Ssl ssl = this.properties.getEnv().getSsl();
267277
if (!ssl.getEnabled()) {
268278
return null;

module/spring-boot-couchbase/src/main/java/org/springframework/boot/couchbase/autoconfigure/CouchbaseConnectionDetails.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.couchbase.autoconfigure;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import org.springframework.boot.autoconfigure.service.connection.ConnectionDetails;
2022
import org.springframework.boot.ssl.SslBundle;
2123

@@ -39,19 +41,19 @@ public interface CouchbaseConnectionDetails extends ConnectionDetails {
3941
* Cluster username.
4042
* @return the cluster username
4143
*/
42-
String getUsername();
44+
@Nullable String getUsername();
4345

4446
/**
4547
* Cluster password.
4648
* @return the cluster password
4749
*/
48-
String getPassword();
50+
@Nullable String getPassword();
4951

5052
/**
5153
* SSL bundle to use.
5254
* @return the SSL bundle to use
5355
*/
54-
default SslBundle getSslBundle() {
56+
default @Nullable SslBundle getSslBundle() {
5557
return null;
5658
}
5759

module/spring-boot-couchbase/src/main/java/org/springframework/boot/couchbase/autoconfigure/CouchbaseProperties.java

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

1919
import java.time.Duration;
2020

21+
import org.jspecify.annotations.Nullable;
22+
2123
import org.springframework.boot.context.properties.ConfigurationProperties;
2224
import org.springframework.util.StringUtils;
2325

@@ -38,43 +40,43 @@ public class CouchbaseProperties {
3840
/**
3941
* Connection string used to locate the Couchbase cluster.
4042
*/
41-
private String connectionString;
43+
private @Nullable String connectionString;
4244

4345
/**
4446
* Cluster username.
4547
*/
46-
private String username;
48+
private @Nullable String username;
4749

4850
/**
4951
* Cluster password.
5052
*/
51-
private String password;
53+
private @Nullable String password;
5254

5355
private final Authentication authentication = new Authentication();
5456

5557
private final Env env = new Env();
5658

57-
public String getConnectionString() {
59+
public @Nullable String getConnectionString() {
5860
return this.connectionString;
5961
}
6062

61-
public void setConnectionString(String connectionString) {
63+
public void setConnectionString(@Nullable String connectionString) {
6264
this.connectionString = connectionString;
6365
}
6466

65-
public String getUsername() {
67+
public @Nullable String getUsername() {
6668
return this.username;
6769
}
6870

69-
public void setUsername(String username) {
71+
public void setUsername(@Nullable String username) {
7072
this.username = username;
7173
}
7274

73-
public String getPassword() {
75+
public @Nullable String getPassword() {
7476
return this.password;
7577
}
7678

77-
public void setPassword(String password) {
79+
public void setPassword(@Nullable String password) {
7880
this.password = password;
7981
}
8082

@@ -105,39 +107,39 @@ public static class Pem {
105107
/**
106108
* PEM-formatted certificates for certificate-based cluster authentication.
107109
*/
108-
private String certificates;
110+
private @Nullable String certificates;
109111

110112
/**
111113
* PEM-formatted private key for certificate-based cluster authentication.
112114
*/
113-
private String privateKey;
115+
private @Nullable String privateKey;
114116

115117
/**
116118
* Private key password for certificate-based cluster authentication.
117119
*/
118-
private String privateKeyPassword;
120+
private @Nullable String privateKeyPassword;
119121

120-
public String getCertificates() {
122+
public @Nullable String getCertificates() {
121123
return this.certificates;
122124
}
123125

124-
public void setCertificates(String certificates) {
126+
public void setCertificates(@Nullable String certificates) {
125127
this.certificates = certificates;
126128
}
127129

128-
public String getPrivateKey() {
130+
public @Nullable String getPrivateKey() {
129131
return this.privateKey;
130132
}
131133

132-
public void setPrivateKey(String privateKey) {
134+
public void setPrivateKey(@Nullable String privateKey) {
133135
this.privateKey = privateKey;
134136
}
135137

136-
public String getPrivateKeyPassword() {
138+
public @Nullable String getPrivateKeyPassword() {
137139
return this.privateKeyPassword;
138140
}
139141

140-
public void setPrivateKeyPassword(String privateKeyPassword) {
142+
public void setPrivateKeyPassword(@Nullable String privateKeyPassword) {
141143
this.privateKeyPassword = privateKeyPassword;
142144
}
143145

@@ -148,26 +150,26 @@ public static class Jks {
148150
/**
149151
* Java KeyStore location for certificate-based cluster authentication.
150152
*/
151-
private String location;
153+
private @Nullable String location;
152154

153155
/**
154156
* Java KeyStore password for certificate-based cluster authentication.
155157
*/
156-
private String password;
158+
private @Nullable String password;
157159

158-
public String getLocation() {
160+
public @Nullable String getLocation() {
159161
return this.location;
160162
}
161163

162-
public void setLocation(String location) {
164+
public void setLocation(@Nullable String location) {
163165
this.location = location;
164166
}
165167

166-
public String getPassword() {
168+
public @Nullable String getPassword() {
167169
return this.password;
168170
}
169171

170-
public void setPassword(String password) {
172+
public void setPassword(@Nullable String password) {
171173
this.password = password;
172174
}
173175

@@ -247,12 +249,12 @@ public static class Ssl {
247249
* Whether to enable SSL support. Enabled automatically if a "bundle" is provided
248250
* unless specified otherwise.
249251
*/
250-
private Boolean enabled;
252+
private @Nullable Boolean enabled;
251253

252254
/**
253255
* SSL bundle name.
254256
*/
255-
private String bundle;
257+
private @Nullable String bundle;
256258

257259
public Boolean getEnabled() {
258260
return (this.enabled != null) ? this.enabled : StringUtils.hasText(this.bundle);
@@ -262,11 +264,11 @@ public void setEnabled(Boolean enabled) {
262264
this.enabled = enabled;
263265
}
264266

265-
public String getBundle() {
267+
public @Nullable String getBundle() {
266268
return this.bundle;
267269
}
268270

269-
public void setBundle(String bundle) {
271+
public void setBundle(@Nullable String bundle) {
270272
this.bundle = bundle;
271273
}
272274

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for Couchbase health.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.couchbase.autoconfigure.health;
22+
23+
import org.jspecify.annotations.NullMarked;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for Couchbase.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.couchbase.autoconfigure;
22+
23+
import org.jspecify.annotations.NullMarked;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Health integration for Couchbase.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.couchbase.health;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-couchbase/src/main/java/org/springframework/boot/couchbase/testcontainers/CouchbaseContainerConnectionDetailsFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.couchbase.testcontainers;
1818

19+
import org.jspecify.annotations.Nullable;
1920
import org.testcontainers.couchbase.CouchbaseContainer;
2021

2122
import org.springframework.boot.couchbase.autoconfigure.CouchbaseConnectionDetails;
@@ -68,7 +69,7 @@ public String getConnectionString() {
6869
}
6970

7071
@Override
71-
public SslBundle getSslBundle() {
72+
public @Nullable SslBundle getSslBundle() {
7273
return super.getSslBundle();
7374
}
7475

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Support for testcontainers Couchbase service connections.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.couchbase.testcontainers;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)