From 49a61e263adddb819dea323a8370f610e32e4385 Mon Sep 17 00:00:00 2001 From: David Grossman Date: Mon, 29 Apr 2024 13:23:55 -0700 Subject: [PATCH] ensure FileReader `close()`es during avro parse (#556) --- .../com/linkedin/avroutil1/parser/avsc/AvscParser.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/parser/src/main/java/com/linkedin/avroutil1/parser/avsc/AvscParser.java b/parser/src/main/java/com/linkedin/avroutil1/parser/avsc/AvscParser.java index d2dfed0f..b7b1a65d 100644 --- a/parser/src/main/java/com/linkedin/avroutil1/parser/avsc/AvscParser.java +++ b/parser/src/main/java/com/linkedin/avroutil1/parser/avsc/AvscParser.java @@ -55,6 +55,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.IOException; import java.io.Reader; import java.nio.file.Path; import java.util.HashMap; @@ -144,13 +145,13 @@ public AvscParseResult parse(Path avscFile) { public AvscParseResult parse(File avscFile) { AvscFileParseContext context = new AvscFileParseContext(avscFile, this); - Reader reader; - try { - reader = new FileReader(avscFile); + try (Reader reader = new FileReader(avscFile)) { + return parse(context, reader); } catch (FileNotFoundException e) { throw new IllegalStateException("input file " + avscFile.getAbsolutePath() + " not found", e); + } catch (IOException e) { + throw new IllegalStateException("error reading input file " + avscFile.getAbsolutePath(), e); } - return parse(context, reader); } private AvscParseResult parse(AvscFileParseContext context, Reader reader) {