Browse Source

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

See gh-46926
pull/46973/head
Moritz Halbritter 4 months ago
parent
commit
49d3bd32c4
  1. 9
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/properties/PushRegistryPropertiesConfigAdapter.java
  2. 12
      module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/ssl/SslMeterBinder.java

9
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/export/properties/PushRegistryPropertiesConfigAdapter.java

@ -43,21 +43,18 @@ public abstract class PushRegistryPropertiesConfigAdapter<T extends PushRegistry @@ -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);
}
}

12
module/spring-boot-micrometer-metrics/src/main/java/org/springframework/boot/micrometer/metrics/autoconfigure/ssl/SslMeterBinder.java

@ -42,6 +42,7 @@ import org.springframework.boot.info.SslInfo.BundleInfo; @@ -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 { @@ -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 { @@ -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.
*/

Loading…
Cancel
Save