diff --git a/spring-context-indexer/src/test/java/org/springframework/context/index/processor/CandidateComponentsIndexerTests.java b/spring-context-indexer/src/test/java/org/springframework/context/index/processor/CandidateComponentsIndexerTests.java index 9b359989cdc..a8d649e3813 100644 --- a/spring-context-indexer/src/test/java/org/springframework/context/index/processor/CandidateComponentsIndexerTests.java +++ b/spring-context-indexer/src/test/java/org/springframework/context/index/processor/CandidateComponentsIndexerTests.java @@ -244,17 +244,18 @@ class CandidateComponentsIndexerTests { } private CandidateComponentsMetadata readGeneratedMetadata(File outputLocation) { - try { - File metadataFile = new File(outputLocation, MetadataStore.METADATA_PATH); - if (metadataFile.isFile()) { - return PropertiesMarshaller.read(new FileInputStream(metadataFile)); + File metadataFile = new File(outputLocation, MetadataStore.METADATA_PATH); + if (metadataFile.isFile()) { + try (FileInputStream fileInputStream = new FileInputStream(metadataFile)) { + CandidateComponentsMetadata metadata = PropertiesMarshaller.read(fileInputStream); + return metadata; } - else { - return new CandidateComponentsMetadata(); + catch (IOException ex) { + throw new IllegalStateException("Failed to read metadata from disk", ex); } } - catch (IOException ex) { - throw new IllegalStateException("Failed to read metadata from disk", ex); + else { + return new CandidateComponentsMetadata(); } }