Closed
Description
Dave Syer opened SPR-12487 and commented
Apparenlty snakeyaml does not close the InputStream you give it, so to prevent problems (especially on Windows), we need to defensively close the stream in YamlProcessor.
This test fails on Windows:
@Test
public void test() throws Exception {
Files.copy(Paths.get("src", "test", "resources", "test.yml"), Paths.get("target", "test.yml"), StandardCopyOption.REPLACE_EXISTING);
new Yaml().loadAll(new FileInputStream("target/test.yml"));
Files.delete(Paths.get("target", "test.yml"));
}
but this one passes:
@Test
public void test() throws Exception {
Files.copy(Paths.get("src", "test", "resources", "test.yml"), Paths.get("target", "test.yml"), StandardCopyOption.REPLACE_EXISTING);
FileInputStream stream = new FileInputStream("target/test.yml");
new Yaml().loadAll(stream);
stream.close();
Files.delete(Paths.get("target", "test.yml"));
}
Discovered by a Spring Cloud user: spring-cloud/spring-cloud-config#45, but will also affect Spring Boot users if they have config files on the file system and then try to delete them.
Affects: 4.1.2
Issue Links:
- YAML Processor leaves StreamDecoder open [SPR-13173] #17765 YAML Processor leaves StreamDecoder open
Referenced from: commits 9a71a0c