Browse Source

Add nullability annotations to module/spring-boot-neo4j

See gh-46587
pull/46675/head
Moritz Halbritter 5 months ago
parent
commit
6fb60bc3f5
  1. 7
      module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/autoconfigure/Neo4jAutoConfiguration.java
  2. 3
      module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/autoconfigure/Neo4jConnectionDetails.java
  3. 44
      module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/autoconfigure/Neo4jProperties.java
  4. 3
      module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/autoconfigure/health/package-info.java
  5. 3
      module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/autoconfigure/package-info.java
  6. 6
      module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/docker/compose/Neo4jDockerComposeConnectionDetailsFactory.java
  7. 7
      module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/docker/compose/Neo4jEnvironment.java
  8. 3
      module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/docker/compose/package-info.java
  9. 5
      module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/health/Neo4jReactiveHealthIndicator.java
  10. 3
      module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/health/package-info.java
  11. 3
      module/spring-boot-neo4j/src/main/java/org/springframework/boot/neo4j/testcontainers/package-info.java

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

@ -23,6 +23,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.jspecify.annotations.Nullable;
import org.neo4j.driver.AuthToken; import org.neo4j.driver.AuthToken;
import org.neo4j.driver.AuthTokenManager; import org.neo4j.driver.AuthTokenManager;
import org.neo4j.driver.AuthTokens; import org.neo4j.driver.AuthTokens;
@ -185,9 +186,9 @@ public final class Neo4jAutoConfiguration {
private final Neo4jProperties properties; private final Neo4jProperties properties;
private final AuthTokenManager authTokenManager; private final @Nullable AuthTokenManager authTokenManager;
PropertiesNeo4jConnectionDetails(Neo4jProperties properties, AuthTokenManager authTokenManager) { PropertiesNeo4jConnectionDetails(Neo4jProperties properties, @Nullable AuthTokenManager authTokenManager) {
this.properties = properties; this.properties = properties;
this.authTokenManager = authTokenManager; this.authTokenManager = authTokenManager;
} }
@ -219,7 +220,7 @@ public final class Neo4jAutoConfiguration {
} }
@Override @Override
public AuthTokenManager getAuthTokenManager() { public @Nullable AuthTokenManager getAuthTokenManager() {
return this.authTokenManager; return this.authTokenManager;
} }

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

@ -18,6 +18,7 @@ package org.springframework.boot.neo4j.autoconfigure;
import java.net.URI; import java.net.URI;
import org.jspecify.annotations.Nullable;
import org.neo4j.driver.AuthToken; import org.neo4j.driver.AuthToken;
import org.neo4j.driver.AuthTokenManager; import org.neo4j.driver.AuthTokenManager;
import org.neo4j.driver.AuthTokens; import org.neo4j.driver.AuthTokens;
@ -55,7 +56,7 @@ public interface Neo4jConnectionDetails extends ConnectionDetails {
* {@code null} in which case the {@link #getAuthToken() auth token} should be used. * {@code null} in which case the {@link #getAuthToken() auth token} should be used.
* @return the auth token manager * @return the auth token manager
*/ */
default AuthTokenManager getAuthTokenManager() { default @Nullable AuthTokenManager getAuthTokenManager() {
return null; return null;
} }

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

@ -20,6 +20,8 @@ import java.io.File;
import java.net.URI; import java.net.URI;
import java.time.Duration; import java.time.Duration;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
/** /**
@ -35,7 +37,7 @@ public class Neo4jProperties {
/** /**
* URI used by the driver. * URI used by the driver.
*/ */
private URI uri; private @Nullable URI uri;
/** /**
* Timeout for borrowing connections from the pool. * Timeout for borrowing connections from the pool.
@ -53,11 +55,11 @@ public class Neo4jProperties {
private final Security security = new Security(); private final Security security = new Security();
public URI getUri() { public @Nullable URI getUri() {
return this.uri; return this.uri;
} }
public void setUri(URI uri) { public void setUri(@Nullable URI uri) {
this.uri = uri; this.uri = uri;
} }
@ -94,53 +96,53 @@ public class Neo4jProperties {
/** /**
* Login user of the server. * Login user of the server.
*/ */
private String username; private @Nullable String username;
/** /**
* Login password of the server. * Login password of the server.
*/ */
private String password; private @Nullable String password;
/** /**
* Realm to connect to. * Realm to connect to.
*/ */
private String realm; private @Nullable String realm;
/** /**
* Kerberos ticket for connecting to the database. Mutual exclusive with a given * Kerberos ticket for connecting to the database. Mutual exclusive with a given
* username. * username.
*/ */
private String kerberosTicket; private @Nullable String kerberosTicket;
public String getUsername() { public @Nullable String getUsername() {
return this.username; return this.username;
} }
public void setUsername(String username) { public void setUsername(@Nullable String username) {
this.username = username; this.username = username;
} }
public String getPassword() { public @Nullable String getPassword() {
return this.password; return this.password;
} }
public void setPassword(String password) { public void setPassword(@Nullable String password) {
this.password = password; this.password = password;
} }
public String getRealm() { public @Nullable String getRealm() {
return this.realm; return this.realm;
} }
public void setRealm(String realm) { public void setRealm(@Nullable String realm) {
this.realm = realm; this.realm = realm;
} }
public String getKerberosTicket() { public @Nullable String getKerberosTicket() {
return this.kerberosTicket; return this.kerberosTicket;
} }
public void setKerberosTicket(String kerberosTicket) { public void setKerberosTicket(@Nullable String kerberosTicket) {
this.kerberosTicket = kerberosTicket; this.kerberosTicket = kerberosTicket;
} }
@ -167,7 +169,7 @@ public class Neo4jProperties {
* Pooled connections that have been idle in the pool for longer than this * Pooled connections that have been idle in the pool for longer than this
* threshold will be tested before they are used again. * threshold will be tested before they are used again.
*/ */
private Duration idleTimeBeforeConnectionTest; private @Nullable Duration idleTimeBeforeConnectionTest;
/** /**
* Pooled connections older than this threshold will be closed and removed from * Pooled connections older than this threshold will be closed and removed from
@ -197,11 +199,11 @@ public class Neo4jProperties {
this.maxConnectionPoolSize = maxConnectionPoolSize; this.maxConnectionPoolSize = maxConnectionPoolSize;
} }
public Duration getIdleTimeBeforeConnectionTest() { public @Nullable Duration getIdleTimeBeforeConnectionTest() {
return this.idleTimeBeforeConnectionTest; return this.idleTimeBeforeConnectionTest;
} }
public void setIdleTimeBeforeConnectionTest(Duration idleTimeBeforeConnectionTest) { public void setIdleTimeBeforeConnectionTest(@Nullable Duration idleTimeBeforeConnectionTest) {
this.idleTimeBeforeConnectionTest = idleTimeBeforeConnectionTest; this.idleTimeBeforeConnectionTest = idleTimeBeforeConnectionTest;
} }
@ -246,7 +248,7 @@ public class Neo4jProperties {
/** /**
* Path to the file that holds the trusted certificates. * Path to the file that holds the trusted certificates.
*/ */
private File certFile; private @Nullable File certFile;
/** /**
* Whether hostname verification is required. * Whether hostname verification is required.
@ -269,11 +271,11 @@ public class Neo4jProperties {
this.trustStrategy = trustStrategy; this.trustStrategy = trustStrategy;
} }
public File getCertFile() { public @Nullable File getCertFile() {
return this.certFile; return this.certFile;
} }
public void setCertFile(File certFile) { public void setCertFile(@Nullable File certFile) {
this.certFile = certFile; this.certFile = certFile;
} }

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

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

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

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

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

@ -18,7 +18,9 @@ package org.springframework.boot.neo4j.docker.compose;
import java.net.URI; import java.net.URI;
import org.jspecify.annotations.Nullable;
import org.neo4j.driver.AuthToken; import org.neo4j.driver.AuthToken;
import org.neo4j.driver.AuthTokens;
import org.springframework.boot.docker.compose.core.RunningService; import org.springframework.boot.docker.compose.core.RunningService;
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory; import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
@ -53,7 +55,7 @@ class Neo4jDockerComposeConnectionDetailsFactory extends DockerComposeConnection
private static final int BOLT_PORT = 7687; private static final int BOLT_PORT = 7687;
private final AuthToken authToken; private final @Nullable AuthToken authToken;
private final URI uri; private final URI uri;
@ -71,7 +73,7 @@ class Neo4jDockerComposeConnectionDetailsFactory extends DockerComposeConnection
@Override @Override
public AuthToken getAuthToken() { public AuthToken getAuthToken() {
return this.authToken; return (this.authToken != null) ? this.authToken : AuthTokens.none();
} }
} }

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

@ -18,6 +18,7 @@ package org.springframework.boot.neo4j.docker.compose;
import java.util.Map; import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.neo4j.driver.AuthToken; import org.neo4j.driver.AuthToken;
import org.neo4j.driver.AuthTokens; import org.neo4j.driver.AuthTokens;
@ -29,7 +30,7 @@ import org.neo4j.driver.AuthTokens;
*/ */
class Neo4jEnvironment { class Neo4jEnvironment {
private final AuthToken authToken; private final @Nullable AuthToken authToken;
Neo4jEnvironment(Map<String, String> env) { Neo4jEnvironment(Map<String, String> env) {
AuthToken authToken = parse(env.get("NEO4J_AUTH")); AuthToken authToken = parse(env.get("NEO4J_AUTH"));
@ -39,7 +40,7 @@ class Neo4jEnvironment {
this.authToken = authToken; this.authToken = authToken;
} }
private AuthToken parse(String neo4jAuth) { private @Nullable AuthToken parse(@Nullable String neo4jAuth) {
if (neo4jAuth == null) { if (neo4jAuth == null) {
return null; return null;
} }
@ -55,7 +56,7 @@ class Neo4jEnvironment {
+ " the neo4j user's password"); + " the neo4j user's password");
} }
AuthToken getAuthToken() { @Nullable AuthToken getAuthToken() {
return this.authToken; return this.authToken;
} }

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

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

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

@ -18,6 +18,7 @@ package org.springframework.boot.neo4j.health;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.neo4j.driver.Driver; import org.neo4j.driver.Driver;
import org.neo4j.driver.Record; import org.neo4j.driver.Record;
import org.neo4j.driver.exceptions.SessionExpiredException; import org.neo4j.driver.exceptions.SessionExpiredException;
@ -31,6 +32,7 @@ import reactor.util.retry.Retry;
import org.springframework.boot.health.contributor.AbstractReactiveHealthIndicator; import org.springframework.boot.health.contributor.AbstractReactiveHealthIndicator;
import org.springframework.boot.health.contributor.Health; import org.springframework.boot.health.contributor.Health;
import org.springframework.boot.health.contributor.ReactiveHealthIndicator; import org.springframework.boot.health.contributor.ReactiveHealthIndicator;
import org.springframework.util.Assert;
/** /**
* {@link ReactiveHealthIndicator} that tests the status of a Neo4j by executing a Cypher * {@link ReactiveHealthIndicator} that tests the status of a Neo4j by executing a Cypher
@ -90,13 +92,14 @@ public final class Neo4jReactiveHealthIndicator extends AbstractReactiveHealthIn
*/ */
private static final class Neo4jHealthDetailsBuilder { private static final class Neo4jHealthDetailsBuilder {
private Record record; private @Nullable Record record;
void record(Record record) { void record(Record record) {
this.record = record; this.record = record;
} }
private Neo4jHealthDetails build(ResultSummary summary) { private Neo4jHealthDetails build(ResultSummary summary) {
Assert.state(this.record != null, "'record' must not be null");
return new Neo4jHealthDetails(this.record, summary); return new Neo4jHealthDetails(this.record, summary);
} }

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

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

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

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

Loading…
Cancel
Save