diff --git a/src/main/java/com/code_intelligence/jazzer/junit/FuzzerDictionary.java b/src/main/java/com/code_intelligence/jazzer/junit/FuzzerDictionary.java index 57e1c1d62..a005b33f7 100644 --- a/src/main/java/com/code_intelligence/jazzer/junit/FuzzerDictionary.java +++ b/src/main/java/com/code_intelligence/jazzer/junit/FuzzerDictionary.java @@ -141,10 +141,11 @@ private static List 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 tokens; + try (BufferedReader reader = new BufferedReader(new InputStreamReader(resourceFile))) { + tokens = reader.lines().collect(Collectors.toList()); + } + return tokens; } catch (IOException e) { throw new UncheckedIOException(e); }