Skip to content

Commit

Permalink
Fix file leak when reading DGS file (#2054)
Browse files Browse the repository at this point in the history
Signed-off-by: Geoffroy Jamgotchian <[email protected]>
  • Loading branch information
geofjamg authored Apr 1, 2022
1 parent 928ad4c commit 6f6812b
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,16 @@ static Optional<StudyCase> load(Path file) {
static Optional<StudyCase> load(String fileName, Supplier<InputStream> inputStreamSupplier) {
Objects.requireNonNull(inputStreamSupplier);
for (StudyCaseLoader studyCaseLoader : ServiceLoader.load(StudyCaseLoader.class)) {
if (fileName.endsWith(studyCaseLoader.getExtension()) &&
studyCaseLoader.test(inputStreamSupplier.get())) {
return Optional.of(studyCaseLoader.doLoad(fileName, inputStreamSupplier.get()));
if (fileName.endsWith(studyCaseLoader.getExtension())) {
try (var testIs = inputStreamSupplier.get()) {
if (studyCaseLoader.test(testIs)) {
try (var loadIs = inputStreamSupplier.get()) {
return Optional.of(studyCaseLoader.doLoad(fileName, loadIs));
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
return Optional.empty();
Expand Down

0 comments on commit 6f6812b

Please sign in to comment.