From 8577718b228a133d24ff0303c8a0607fde64eeed Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 26 Feb 2025 13:03:28 +0000 Subject: [PATCH] Close InputStream when loading PEM content from a resource Fixes gh-44443 --- .../java/org/springframework/boot/ssl/pem/PemContent.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemContent.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemContent.java index cadb6b215a..ebdc4f4ce0 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemContent.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/ssl/pem/PemContent.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2024 the original author or authors. + * Copyright 2012-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -118,8 +118,8 @@ public final class PemContent { if (isPresentInText(content)) { return new PemContent(content); } - try { - return load(resourceLoader.getResource(content).getInputStream()); + try (InputStream in = resourceLoader.getResource(content).getInputStream()) { + return load(in); } catch (IOException | UncheckedIOException ex) { throw new IOException("Error reading certificate or key from file '%s'".formatted(content), ex);