Skip to content

Need a defensive close() in YamlProcessor [SPR-12487] #17093

Closed
@spring-projects-issues

Description

@spring-projects-issues

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:

Referenced from: commits 9a71a0c

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions