Add nullability annotations to module/spring-boot-hazelcast

See gh-46587
This commit is contained in:
Moritz Halbritter
2025-08-01 09:16:11 +02:00
parent 363ddb5115
commit 81c0bfb048
8 changed files with 34 additions and 11 deletions
@@ -22,12 +22,14 @@ import java.net.URL;
import com.hazelcast.client.config.ClientConfigRecognizer;
import com.hazelcast.config.ConfigStream;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.autoconfigure.condition.ConditionMessage.Builder;
import org.springframework.boot.autoconfigure.condition.ConditionOutcome;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.util.Assert;
/**
* {@link HazelcastConfigResourceCondition} that checks if the
@@ -56,8 +58,10 @@ class HazelcastClientConfigAvailableCondition extends HazelcastConfigResourceCon
static class HazelcastClientValidation {
static ConditionOutcome clientConfigOutcome(ConditionContext context, String propertyName, Builder builder) {
static @Nullable ConditionOutcome clientConfigOutcome(ConditionContext context, String propertyName,
Builder builder) {
String resourcePath = context.getEnvironment().getProperty(propertyName);
Assert.state(resourcePath != null, "'resourcePath' must not be null");
Resource resource = context.getResourceLoader().getResource(resourcePath);
if (!resource.exists()) {
return ConditionOutcome.noMatch(builder.because("Hazelcast configuration does not exist"));
@@ -16,6 +16,8 @@
package org.springframework.boot.hazelcast.autoconfigure;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
@@ -32,13 +34,13 @@ public class HazelcastProperties {
/**
* The location of the configuration file to use to initialize Hazelcast.
*/
private Resource config;
private @Nullable Resource config;
public Resource getConfig() {
public @Nullable Resource getConfig() {
return this.config;
}
public void setConfig(Resource config) {
public void setConfig(@Nullable Resource config) {
this.config = config;
}
@@ -48,13 +50,13 @@ public class HazelcastProperties {
* @throws IllegalArgumentException if the config attribute is set to an unknown
* location
*/
public Resource resolveConfigLocation() {
if (this.config == null) {
public @Nullable Resource resolveConfigLocation() {
Resource config = this.config;
if (config == null) {
return null;
}
Assert.state(this.config.exists(),
() -> "Hazelcast configuration does not exist '" + this.config.getDescription() + "'");
return this.config;
Assert.state(config.exists(), () -> "Hazelcast configuration does not exist '" + config.getDescription() + "'");
return config;
}
}
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Hazelcast health.
*/
@NullMarked
package org.springframework.boot.hazelcast.autoconfigure.health;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Hazelcast.
*/
@NullMarked
package org.springframework.boot.hazelcast.autoconfigure;
import org.jspecify.annotations.NullMarked;
@@ -18,6 +18,8 @@ package org.springframework.boot.hazelcast.docker.compose;
import java.util.Map;
import org.jspecify.annotations.Nullable;
/**
* Hazelcast environment details.
*
@@ -25,13 +27,13 @@ import java.util.Map;
*/
class HazelcastEnvironment {
private final String clusterName;
private final @Nullable String clusterName;
HazelcastEnvironment(Map<String, String> env) {
this.clusterName = env.get("HZ_CLUSTERNAME");
}
String getClusterName() {
@Nullable String getClusterName() {
return this.clusterName;
}
@@ -17,4 +17,7 @@
/**
* Support for Docker Compose Hazelcast service connections.
*/
@NullMarked
package org.springframework.boot.hazelcast.docker.compose;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Health integration for Hazelcast.
*/
@NullMarked
package org.springframework.boot.hazelcast.health;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Support for testcontainers Hazelcast service connections.
*/
@NullMarked
package org.springframework.boot.hazelcast.testcontainers;
import org.jspecify.annotations.NullMarked;