From 2631cd0860dfcb71bd5b2b1e47c2e8f8a62894aa Mon Sep 17 00:00:00 2001 From: David Grossman Date: Mon, 29 Apr 2024 12:28:30 -0700 Subject: [PATCH 1/4] ensure FileReader `close()`es during avro parse --- .../com/linkedin/avroutil1/parser/avsc/AvscParser.java | 7 +++---- 1 file changed, 3 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..03b6b753 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 @@ -144,13 +144,12 @@ 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); } - return parse(context, reader); } private AvscParseResult parse(AvscFileParseContext context, Reader reader) { From 33d03cb82aa1274c5dfaf4f9fae1938f6708804f Mon Sep 17 00:00:00 2001 From: David Grossman Date: Mon, 29 Apr 2024 12:35:03 -0700 Subject: [PATCH 2/4] catch ioexception --- .../java/com/linkedin/avroutil1/parser/avsc/AvscParser.java | 2 ++ 1 file changed, 2 insertions(+) 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 03b6b753..39210f60 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 @@ -149,6 +149,8 @@ public AvscParseResult parse(File 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); } } From d96b539e9fefb73d9ce6e0159d3830ad7aa356b1 Mon Sep 17 00:00:00 2001 From: David Grossman Date: Mon, 29 Apr 2024 12:36:05 -0700 Subject: [PATCH 3/4] cleanup empty line --- .../main/java/com/linkedin/avroutil1/parser/avsc/AvscParser.java | 1 - 1 file changed, 1 deletion(-) 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 39210f60..386fa53d 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 @@ -144,7 +144,6 @@ public AvscParseResult parse(Path avscFile) { public AvscParseResult parse(File avscFile) { AvscFileParseContext context = new AvscFileParseContext(avscFile, this); - ; try (Reader reader = new FileReader(avscFile)) { return parse(context, reader); } catch (FileNotFoundException e) { From ca04a6557e55a492a0917594ee6578c00c1008aa Mon Sep 17 00:00:00 2001 From: David Grossman Date: Mon, 29 Apr 2024 12:39:53 -0700 Subject: [PATCH 4/4] Update AvscParser.java --- .../main/java/com/linkedin/avroutil1/parser/avsc/AvscParser.java | 1 + 1 file changed, 1 insertion(+) 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 386fa53d..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;