check first the filesize before opening a Reader to the config file

This commit is contained in:
Armin Schrenk
2026-01-28 17:32:10 +01:00
parent efbd107fb5
commit 19c9eada9d

View File

@@ -92,11 +92,13 @@ class AdminPropertiesSetter {
//visible for testing
static Properties loadAdminProperties(Path adminPropertiesPath) {
var adminProps = new Properties();
try (var reader = Files.newBufferedReader(adminPropertiesPath, StandardCharsets.UTF_8)) {
if(Files.size(adminPropertiesPath) > MAX_CONFIG_SIZE_BYTES) {
try {
if (Files.size(adminPropertiesPath) > MAX_CONFIG_SIZE_BYTES) {
throw new IOException("Config file %s exceeds maximum size of %d".formatted(adminPropertiesPath, MAX_CONFIG_SIZE_BYTES));
}
adminProps.load(reader);
try (var reader = Files.newBufferedReader(adminPropertiesPath, StandardCharsets.UTF_8)) {
adminProps.load(reader);
}
} catch (NoSuchFileException _) {
//NO-OP
LOG.debug("No admin properties found at {}.", adminPropertiesPath);