Improve null-safety of module/spring-boot-metrics

See gh-46926
This commit is contained in:
Moritz Halbritter
2025-08-26 14:22:55 +02:00
parent f1ed5098a3
commit 49d3bd32c4
2 changed files with 13 additions and 8 deletions
@@ -43,21 +43,18 @@ public abstract class PushRegistryPropertiesConfigAdapter<T extends PushRegistry
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public Duration step() {
return get(T::getStep, PushRegistryConfig.super::step);
return getRequired(T::getStep, PushRegistryConfig.super::step);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public boolean enabled() {
return get(T::isEnabled, PushRegistryConfig.super::enabled);
return getRequired(T::isEnabled, PushRegistryConfig.super::enabled);
}
@Override
@SuppressWarnings("NullAway") // Lambda isn't detected with the correct nullability
public int batchSize() {
return get(T::getBatchSize, PushRegistryConfig.super::batchSize);
return getRequired(T::getBatchSize, PushRegistryConfig.super::batchSize);
}
}
@@ -42,6 +42,7 @@ import org.springframework.boot.info.SslInfo.BundleInfo;
import org.springframework.boot.info.SslInfo.CertificateChainInfo;
import org.springframework.boot.info.SslInfo.CertificateInfo;
import org.springframework.boot.ssl.SslBundles;
import org.springframework.util.Assert;
/**
* {@link MeterBinder} which registers the SSL chain expiry (soonest to expire certificate
@@ -102,7 +103,8 @@ class SslMeterBinder implements MeterBinder {
private @Nullable Row<CertificateInfo> createRowForChain(BundleInfo bundle, CertificateChainInfo chain) {
CertificateInfo leastValidCertificate = chain.getCertificates()
.stream()
.min(Comparator.comparing(CertificateInfo::getValidityEnds))
.filter((c) -> c.getValidityEnds() != null)
.min(Comparator.comparing(this::getValidityEnds))
.orElse(null);
if (leastValidCertificate == null) {
return null;
@@ -114,10 +116,16 @@ class SslMeterBinder implements MeterBinder {
}
private long getChainExpiry(CertificateInfo certificate) {
Duration valid = Duration.between(Instant.now(this.clock), certificate.getValidityEnds());
Duration valid = Duration.between(Instant.now(this.clock), getValidityEnds(certificate));
return valid.get(ChronoUnit.SECONDS);
}
private Instant getValidityEnds(CertificateInfo certificate) {
Instant validityEnds = certificate.getValidityEnds();
Assert.state(validityEnds != null, "'validityEnds' must not be null");
return validityEnds;
}
/**
* Manages bundles and their metrics.
*/