mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-24 02:09:05 +00:00
Improve null-safety of module/spring-boot-metrics
See gh-46926
This commit is contained in:
+3
-6
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-2
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user