Skip to content

Commit 9a48250

Browse files
committed
Fix a few possible null dereferences by adding additional checks
1 parent 75f3d2a commit 9a48250

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/main/java/core/FileOperations.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ public static Set<Path> listFiles(Path dir, FileExtension extension) throws IOEx
9393
if (path == null || path.getFileName() == null) {
9494
continue; // Skip null paths
9595
}
96-
String fileName = path.getFileName().toString();
97-
if (!Files.isDirectory(path) && !FilePaths.IGNORED_FILES.contains(fileName)
96+
Path fileName = path.getFileName();
97+
if (fileName == null) return null;
98+
if (!Files.isDirectory(path) && !FilePaths.IGNORED_FILES.contains(fileName.toString())
9899
&& fileName.endsWith(extension.getExtension())) {
99100
pathSet.add(dir.resolve(fileName));
100101
}

src/main/java/core/JSONProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ public class JSONProcessor {
3939
public static JSONObject processJson(Path path) {
4040
if (path == null) return null;
4141
List<String> contents = FileOperations.readFile(path);
42-
String key = path.getFileName().toString().split("\\.")[0];
42+
Path fileName = path.getFileName();
43+
if (fileName == null) return null;
44+
String key = fileName.toString().split("\\.")[0];
4345
return processJson(key, contents);
4446
}
4547

0 commit comments

Comments
 (0)