2020
2121import java .io .IOException ;
2222import java .nio .file .Files ;
23+ import java .nio .file .InvalidPathException ;
2324import java .nio .file .Path ;
2425import java .nio .file .Paths ;
26+ import java .util .Locale ;
2527import java .util .logging .Level ;
2628import java .util .logging .Logger ;
2729
@@ -54,7 +56,7 @@ public static void processFile(String inputPdfName, Config config) throws IOExce
5456 *
5557 * @param inputPdfName the path to the input file
5658 * @return {@code true} if the path is non-null, points to an existing
57- * regular file, and has a .pdf extension; {@code false} otherwise
59+ * regular file, and has a .pdf extension; {@code false} otherwise
5860 */
5961 private static boolean isValidInputFile (String inputPdfName ) {
6062
@@ -63,7 +65,14 @@ private static boolean isValidInputFile(String inputPdfName) {
6365 return false ;
6466 }
6567
66- Path path = Paths .get (inputPdfName );
68+ final Path path ;
69+
70+ try {
71+ path = Paths .get (inputPdfName );
72+ } catch (InvalidPathException ex ) {
73+ LOGGER .log (Level .WARNING , () -> "Invalid file path: " + inputPdfName );
74+ return false ;
75+ }
6776
6877 if (!Files .exists (path )) {
6978 LOGGER .log (Level .WARNING , () -> "File does not exist: " + inputPdfName );
@@ -75,7 +84,7 @@ private static boolean isValidInputFile(String inputPdfName) {
7584 return false ;
7685 }
7786
78- if (!inputPdfName . toLowerCase ().endsWith (".pdf" )) {
87+ if (!path . getFileName (). toString (). toLowerCase (Locale . ROOT ).endsWith (".pdf" )) {
7988 LOGGER .log (Level .WARNING , () -> "Not a PDF file: " + inputPdfName );
8089 return false ;
8190 }
0 commit comments