Skip to content

Commit

Permalink
Make resource reader's closure more explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
br-lewis committed Oct 9, 2023
1 parent aaff2ea commit a6bb281
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ private static List<String> tokensFromResource(String absoluteResourcePath) {
if (resourceFile == null) {
throw new FileNotFoundException(absoluteResourcePath);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(resourceFile));
// I think returning just reader.lines() results in the file stream being closed before it's
// read, so we immediately read the file and collect the lines into a list
return reader.lines().collect(Collectors.toList());
List<String> tokens;
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resourceFile))) {
tokens = reader.lines().collect(Collectors.toList());
}
return tokens;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
Expand Down

0 comments on commit a6bb281

Please sign in to comment.