Skip to content

Commit 6fb60bc

Browse files
committed
Add nullability annotations to module/spring-boot-neo4j
See gh-46587
1 parent 38acdf3 commit 6fb60bc

File tree

11 files changed

+56
-31
lines changed

11 files changed

+56
-31
lines changed

module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/autoconfigure/Neo4jAutoConfiguration.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Locale;
2424
import java.util.concurrent.TimeUnit;
2525

26+
import org.jspecify.annotations.Nullable;
2627
import org.neo4j.driver.AuthToken;
2728
import org.neo4j.driver.AuthTokenManager;
2829
import org.neo4j.driver.AuthTokens;
@@ -185,9 +186,9 @@ static class PropertiesNeo4jConnectionDetails implements Neo4jConnectionDetails
185186

186187
private final Neo4jProperties properties;
187188

188-
private final AuthTokenManager authTokenManager;
189+
private final @Nullable AuthTokenManager authTokenManager;
189190

190-
PropertiesNeo4jConnectionDetails(Neo4jProperties properties, AuthTokenManager authTokenManager) {
191+
PropertiesNeo4jConnectionDetails(Neo4jProperties properties, @Nullable AuthTokenManager authTokenManager) {
191192
this.properties = properties;
192193
this.authTokenManager = authTokenManager;
193194
}
@@ -219,7 +220,7 @@ public AuthToken getAuthToken() {
219220
}
220221

221222
@Override
222-
public AuthTokenManager getAuthTokenManager() {
223+
public @Nullable AuthTokenManager getAuthTokenManager() {
223224
return this.authTokenManager;
224225
}
225226

module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/autoconfigure/Neo4jConnectionDetails.java

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

1919
import java.net.URI;
2020

21+
import org.jspecify.annotations.Nullable;
2122
import org.neo4j.driver.AuthToken;
2223
import org.neo4j.driver.AuthTokenManager;
2324
import org.neo4j.driver.AuthTokens;
@@ -55,7 +56,7 @@ default AuthToken getAuthToken() {
5556
* {@code null} in which case the {@link #getAuthToken() auth token} should be used.
5657
* @return the auth token manager
5758
*/
58-
default AuthTokenManager getAuthTokenManager() {
59+
default @Nullable AuthTokenManager getAuthTokenManager() {
5960
return null;
6061
}
6162

module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/autoconfigure/Neo4jProperties.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.net.URI;
2121
import java.time.Duration;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.boot.context.properties.ConfigurationProperties;
2426

2527
/**
@@ -35,7 +37,7 @@ public class Neo4jProperties {
3537
/**
3638
* URI used by the driver.
3739
*/
38-
private URI uri;
40+
private @Nullable URI uri;
3941

4042
/**
4143
* Timeout for borrowing connections from the pool.
@@ -53,11 +55,11 @@ public class Neo4jProperties {
5355

5456
private final Security security = new Security();
5557

56-
public URI getUri() {
58+
public @Nullable URI getUri() {
5759
return this.uri;
5860
}
5961

60-
public void setUri(URI uri) {
62+
public void setUri(@Nullable URI uri) {
6163
this.uri = uri;
6264
}
6365

@@ -94,53 +96,53 @@ public static class Authentication {
9496
/**
9597
* Login user of the server.
9698
*/
97-
private String username;
99+
private @Nullable String username;
98100

99101
/**
100102
* Login password of the server.
101103
*/
102-
private String password;
104+
private @Nullable String password;
103105

104106
/**
105107
* Realm to connect to.
106108
*/
107-
private String realm;
109+
private @Nullable String realm;
108110

109111
/**
110112
* Kerberos ticket for connecting to the database. Mutual exclusive with a given
111113
* username.
112114
*/
113-
private String kerberosTicket;
115+
private @Nullable String kerberosTicket;
114116

115-
public String getUsername() {
117+
public @Nullable String getUsername() {
116118
return this.username;
117119
}
118120

119-
public void setUsername(String username) {
121+
public void setUsername(@Nullable String username) {
120122
this.username = username;
121123
}
122124

123-
public String getPassword() {
125+
public @Nullable String getPassword() {
124126
return this.password;
125127
}
126128

127-
public void setPassword(String password) {
129+
public void setPassword(@Nullable String password) {
128130
this.password = password;
129131
}
130132

131-
public String getRealm() {
133+
public @Nullable String getRealm() {
132134
return this.realm;
133135
}
134136

135-
public void setRealm(String realm) {
137+
public void setRealm(@Nullable String realm) {
136138
this.realm = realm;
137139
}
138140

139-
public String getKerberosTicket() {
141+
public @Nullable String getKerberosTicket() {
140142
return this.kerberosTicket;
141143
}
142144

143-
public void setKerberosTicket(String kerberosTicket) {
145+
public void setKerberosTicket(@Nullable String kerberosTicket) {
144146
this.kerberosTicket = kerberosTicket;
145147
}
146148

@@ -167,7 +169,7 @@ public static class Pool {
167169
* Pooled connections that have been idle in the pool for longer than this
168170
* threshold will be tested before they are used again.
169171
*/
170-
private Duration idleTimeBeforeConnectionTest;
172+
private @Nullable Duration idleTimeBeforeConnectionTest;
171173

172174
/**
173175
* Pooled connections older than this threshold will be closed and removed from
@@ -197,11 +199,11 @@ public void setMaxConnectionPoolSize(int maxConnectionPoolSize) {
197199
this.maxConnectionPoolSize = maxConnectionPoolSize;
198200
}
199201

200-
public Duration getIdleTimeBeforeConnectionTest() {
202+
public @Nullable Duration getIdleTimeBeforeConnectionTest() {
201203
return this.idleTimeBeforeConnectionTest;
202204
}
203205

204-
public void setIdleTimeBeforeConnectionTest(Duration idleTimeBeforeConnectionTest) {
206+
public void setIdleTimeBeforeConnectionTest(@Nullable Duration idleTimeBeforeConnectionTest) {
205207
this.idleTimeBeforeConnectionTest = idleTimeBeforeConnectionTest;
206208
}
207209

@@ -246,7 +248,7 @@ public static class Security {
246248
/**
247249
* Path to the file that holds the trusted certificates.
248250
*/
249-
private File certFile;
251+
private @Nullable File certFile;
250252

251253
/**
252254
* Whether hostname verification is required.
@@ -269,11 +271,11 @@ public void setTrustStrategy(TrustStrategy trustStrategy) {
269271
this.trustStrategy = trustStrategy;
270272
}
271273

272-
public File getCertFile() {
274+
public @Nullable File getCertFile() {
273275
return this.certFile;
274276
}
275277

276-
public void setCertFile(File certFile) {
278+
public void setCertFile(@Nullable File certFile) {
277279
this.certFile = certFile;
278280
}
279281

module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/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 Neo4j health.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.neo4j.autoconfigure.health;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/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 Neo4j.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.neo4j.autoconfigure;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/docker/compose/Neo4jDockerComposeConnectionDetailsFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
import java.net.URI;
2020

21+
import org.jspecify.annotations.Nullable;
2122
import org.neo4j.driver.AuthToken;
23+
import org.neo4j.driver.AuthTokens;
2224

2325
import org.springframework.boot.docker.compose.core.RunningService;
2426
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
@@ -53,7 +55,7 @@ static class Neo4jDockerComposeConnectionDetails extends DockerComposeConnection
5355

5456
private static final int BOLT_PORT = 7687;
5557

56-
private final AuthToken authToken;
58+
private final @Nullable AuthToken authToken;
5759

5860
private final URI uri;
5961

@@ -71,7 +73,7 @@ public URI getUri() {
7173

7274
@Override
7375
public AuthToken getAuthToken() {
74-
return this.authToken;
76+
return (this.authToken != null) ? this.authToken : AuthTokens.none();
7577
}
7678

7779
}

module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/docker/compose/Neo4jEnvironment.java

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

1919
import java.util.Map;
2020

21+
import org.jspecify.annotations.Nullable;
2122
import org.neo4j.driver.AuthToken;
2223
import org.neo4j.driver.AuthTokens;
2324

@@ -29,7 +30,7 @@
2930
*/
3031
class Neo4jEnvironment {
3132

32-
private final AuthToken authToken;
33+
private final @Nullable AuthToken authToken;
3334

3435
Neo4jEnvironment(Map<String, String> env) {
3536
AuthToken authToken = parse(env.get("NEO4J_AUTH"));
@@ -39,7 +40,7 @@ class Neo4jEnvironment {
3940
this.authToken = authToken;
4041
}
4142

42-
private AuthToken parse(String neo4jAuth) {
43+
private @Nullable AuthToken parse(@Nullable String neo4jAuth) {
4344
if (neo4jAuth == null) {
4445
return null;
4546
}
@@ -55,7 +56,7 @@ private AuthToken parse(String neo4jAuth) {
5556
+ " the neo4j user's password");
5657
}
5758

58-
AuthToken getAuthToken() {
59+
@Nullable AuthToken getAuthToken() {
5960
return this.authToken;
6061
}
6162

module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/docker/compose/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 Docker Compose Neo4J service connections.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.neo4j.docker.compose;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/health/Neo4jReactiveHealthIndicator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
21+
import org.jspecify.annotations.Nullable;
2122
import org.neo4j.driver.Driver;
2223
import org.neo4j.driver.Record;
2324
import org.neo4j.driver.exceptions.SessionExpiredException;
@@ -31,6 +32,7 @@
3132
import org.springframework.boot.health.contributor.AbstractReactiveHealthIndicator;
3233
import org.springframework.boot.health.contributor.Health;
3334
import org.springframework.boot.health.contributor.ReactiveHealthIndicator;
35+
import org.springframework.util.Assert;
3436

3537
/**
3638
* {@link ReactiveHealthIndicator} that tests the status of a Neo4j by executing a Cypher
@@ -90,13 +92,14 @@ private Mono<? extends Neo4jHealthDetails> healthDetails(ReactiveResult result)
9092
*/
9193
private static final class Neo4jHealthDetailsBuilder {
9294

93-
private Record record;
95+
private @Nullable Record record;
9496

9597
void record(Record record) {
9698
this.record = record;
9799
}
98100

99101
private Neo4jHealthDetails build(ResultSummary summary) {
102+
Assert.state(this.record != null, "'record' must not be null");
100103
return new Neo4jHealthDetails(this.record, summary);
101104
}
102105

module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/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 Neo4j.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.neo4j.health;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)