Skip to content

Commit fe52df9

Browse files
committed
Move DiskSpaceHealthIndicator path checks
By moving the exists and readable checks from DiskSpaceHealthIndicatorProperties to DiskSpaceHealthIndicator they are executed later. This gives the application the possibility to access the configured path and to create it before the DiskSpaceHealthIndicator actually needs it.
1 parent 286b9f8 commit fe52df9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/system/DiskSpaceHealthContributorAutoConfiguration.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.system;
1818

19+
import java.io.File;
20+
1921
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
2022
import org.springframework.boot.actuate.autoconfigure.health.HealthContributorAutoConfiguration;
2123
import org.springframework.boot.actuate.system.DiskSpaceHealthIndicator;
@@ -25,6 +27,7 @@
2527
import org.springframework.boot.context.properties.EnableConfigurationProperties;
2628
import org.springframework.context.annotation.Bean;
2729
import org.springframework.context.annotation.Configuration;
30+
import org.springframework.util.Assert;
2831

2932
/**
3033
* {@link EnableAutoConfiguration Auto-configuration} for
@@ -43,7 +46,12 @@ public class DiskSpaceHealthContributorAutoConfiguration {
4346
@Bean
4447
@ConditionalOnMissingBean(name = "diskSpaceHealthIndicator")
4548
public DiskSpaceHealthIndicator diskSpaceHealthIndicator(DiskSpaceHealthIndicatorProperties properties) {
46-
return new DiskSpaceHealthIndicator(properties.getPath(), properties.getThreshold());
49+
File path = properties.getPath();
50+
51+
Assert.isTrue(path.exists(), () -> "Path '" + path + "' does not exist");
52+
Assert.isTrue(path.canRead(), () -> "Path '" + path + "' cannot be read");
53+
54+
return new DiskSpaceHealthIndicator(path, properties.getThreshold());
4755
}
4856

4957
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/system/DiskSpaceHealthIndicatorProperties.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ public File getPath() {
4848
}
4949

5050
public void setPath(File path) {
51-
Assert.isTrue(path.exists(), () -> "Path '" + path + "' does not exist");
52-
Assert.isTrue(path.canRead(), () -> "Path '" + path + "' cannot be read");
5351
this.path = path;
5452
}
5553

0 commit comments

Comments
 (0)