Fix unclosed streams
* make sure Files.path() properly closes its directory, using try-with-resources * missing one, found by @violetagg * cherry pick from1abd516456andec894cb82f
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-bindings</artifactId>
|
||||
<version>${version}</version>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* A representation of a binding as defined by the
|
||||
@@ -114,13 +115,12 @@ public final class Binding {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
try {
|
||||
return Files.list(path)
|
||||
.filter(p -> {
|
||||
try (Stream<Path> paths = Files.list(path)) {
|
||||
return paths.filter(p -> {
|
||||
try {
|
||||
return !Files.isHidden(p);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(String.format("unable to determine id file '%s' is hidden", p), e);
|
||||
throw new IllegalStateException(String.format("unable to determine if file '%s' is hidden", p), e);
|
||||
}
|
||||
})
|
||||
.filter(p -> !Files.isDirectory(p))
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
||||
/**
|
||||
@@ -81,8 +82,8 @@ public final class Bindings {
|
||||
throw new IllegalArgumentException(String.format("%s is not a directory", p));
|
||||
}
|
||||
|
||||
try {
|
||||
this.bindings = Files.list(p)
|
||||
try (Stream<Path> paths = Files.list(p)) {
|
||||
this.bindings = paths
|
||||
.map(Binding::new)
|
||||
.collect(Collectors.toList());
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user