From 07e869c5a6aa54eabdc9d1c8a953e8789f46b611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20M=C3=A9a?= Date: Tue, 1 Sep 2026 15:37:54 -0400 Subject: [PATCH 1/2] Fail on empty required files --- .../org/mtransit/parser/gtfs/GReader.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/mtransit/parser/gtfs/GReader.java b/src/main/java/org/mtransit/parser/gtfs/GReader.java index 32b0554..4181811 100644 --- a/src/main/java/org/mtransit/parser/gtfs/GReader.java +++ b/src/main/java/org/mtransit/parser/gtfs/GReader.java @@ -242,14 +242,17 @@ private static boolean readFiles( final File gtfsFile = FileUtils.findFileCaseInsensitive(gtfsDir, fileNames); if (gtfsFile == null || !gtfsFile.exists()) { if (fileRequired) { - throw new MTLog.Fatal("'%s' file does not exist!", fileNames); + throw new MTLog.Fatal("'%s' required file does not exist!", fileNames); } else { MTLog.log("Reading file(s) '%s'... SKIP (non-existing).", fileNames); return false; } } try (BufferedReader br = Files.newBufferedReader(gtfsFile.toPath())) { - readCsv(gtfsFile.getName(), br, lineProcessor, onColumnNamesFoundCallback); + final int linesProcessedCount = readCsv(gtfsFile.getName(), br, lineProcessor, onColumnNamesFoundCallback); + if (fileRequired && linesProcessedCount <= 0) { + throw new MTLog.Fatal("'%s' required file is empty!", gtfsFile); + } } catch (IOException ioe) { throw new MTLog.Fatal(ioe, "I/O Error while reading GTFS file %s!", gtfsFile); } @@ -266,13 +269,8 @@ private static boolean readFiles( private static final Pattern QUOTE_ = Pattern.compile("\""); - @SuppressWarnings("unused") - private static void readCsv(String filename, BufferedReader reader, LineProcessor lineProcessor) throws IOException { - readCsv(filename, reader, lineProcessor, null); - } - @SuppressWarnings("resource") - private static void readCsv( + private static int readCsv( String filename, BufferedReader reader, LineProcessor lineProcessor, @@ -282,7 +280,7 @@ private static void readCsv( String line; String[] columnNames; line = reader.readLine(); - if (line == null || line.isEmpty()) return; + if (line == null || line.isEmpty()) return 0; if (line.charAt(0) == '\uFEFF') { // remove 1st empty char MTLog.log("Reading file '%s'... > remove 1st empty car", filename); line = String.copyValueOf(line.toCharArray(), 1, line.length() - 1); @@ -295,7 +293,7 @@ private static void readCsv( if (onColumnNamesFoundCallback != null) { onColumnNamesFoundCallback.processColumnNames(Arrays.asList(columnNames)); } - if (columnNames.length == 0) return; + if (columnNames.length == 0) return 0; List lineRecords; final HashMap map = new HashMap<>(); int l = 0; @@ -346,6 +344,7 @@ private static void readCsv( } // LOG } MTLog.log("Reading file '%s' (lines: %s)... DONE", filename, l); + return l; } private static void processStopTime( From 366d74ba32a7925d3842edf582fbf5e5d0d4aad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20M=C3=A9a?= Date: Tue, 1 Sep 2026 15:45:51 -0400 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/main/java/org/mtransit/parser/gtfs/GReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/mtransit/parser/gtfs/GReader.java b/src/main/java/org/mtransit/parser/gtfs/GReader.java index 4181811..d867102 100644 --- a/src/main/java/org/mtransit/parser/gtfs/GReader.java +++ b/src/main/java/org/mtransit/parser/gtfs/GReader.java @@ -282,7 +282,7 @@ private static int readCsv( line = reader.readLine(); if (line == null || line.isEmpty()) return 0; if (line.charAt(0) == '\uFEFF') { // remove 1st empty char - MTLog.log("Reading file '%s'... > remove 1st empty car", filename); + MTLog.log("Reading file '%s'... > remove 1st empty char", filename); line = String.copyValueOf(line.toCharArray(), 1, line.length() - 1); } CSVRecord lineRecordColumns = CSVParser.parse(line, CSV_FORMAT).getRecords().get(0);