Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spring-projects-issues opened this issue Dec 1, 2014 · 0 comments
Closed

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

spring-projects-issues opened this issue Dec 1, 2014 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Dec 1, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants