From 17ae4f56b815c7ad0a35f6e003f051b2fed35808 Mon Sep 17 00:00:00 2001 From: Chris Mair Date: Tue, 14 May 2024 21:14:18 -0400 Subject: [PATCH] #20: `AbstractFakeFileSystem`: Fix NullPointerException in `listFiles()` and `listNames()` if file was deleted or renamed. --- CHANGELOG.md | 1 + .../fake/filesystem/AbstractFakeFileSystem.java | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e00507..791e381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ TODO: Version 3.2.0 (??? 2023) ------------------------------------------ - #21: FakeFtpServer: Add support for the SIZE command.([Edoardo Luppi](https://github.com/lppedd)) + - #20: `AbstractFakeFileSystem`: Fix NullPointerException in `listFiles()` and `listNames()` if file was deleted or renamed. Infrastructure and Dependencies - Upgrade Spring Framework test dependency to 5.3.30. diff --git a/src/main/java/org/mockftpserver/fake/filesystem/AbstractFakeFileSystem.java b/src/main/java/org/mockftpserver/fake/filesystem/AbstractFakeFileSystem.java index f180824..822f704 100644 --- a/src/main/java/org/mockftpserver/fake/filesystem/AbstractFakeFileSystem.java +++ b/src/main/java/org/mockftpserver/fake/filesystem/AbstractFakeFileSystem.java @@ -220,7 +220,9 @@ public List listFiles(String path) { while (iter.hasNext()) { String childPath = (String) iter.next(); FileSystemEntry fileSystemEntry = getEntry(childPath); - entryList.add(fileSystemEntry); + if (fileSystemEntry != null) { + entryList.add(fileSystemEntry); + } } return entryList; } @@ -249,7 +251,9 @@ public List listNames(String path) { while (iter.hasNext()) { String childPath = (String) iter.next(); FileSystemEntry fileSystemEntry = getEntry(childPath); - filenames.add(fileSystemEntry.getName()); + if (fileSystemEntry != null) { + filenames.add(fileSystemEntry.getName()); + } } return filenames; }