This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-net.git


The following commit(s) were added to refs/heads/master by this push:
     new 0498eaf  Fix possible NPEs in tests.
0498eaf is described below

commit 0498eafb47104b633b646a2e4af0a372379007dd
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Feb 12 10:57:55 2021 -0500

    Fix possible NPEs in tests.
---
 .../org/apache/commons/net/examples/MainTest.java  | 13 ++++----
 .../commons/net/ftp/parser/MLSDComparison.java     | 35 ++++++++++++----------
 2 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/src/test/java/org/apache/commons/net/examples/MainTest.java 
b/src/test/java/org/apache/commons/net/examples/MainTest.java
index e09ac74..ff300b8 100644
--- a/src/test/java/org/apache/commons/net/examples/MainTest.java
+++ b/src/test/java/org/apache/commons/net/examples/MainTest.java
@@ -80,11 +80,14 @@ public class MainTest {
     }
 
     private static void scanForClasses(final int rootLength, final File 
current, final Properties p) {
-        for(final File file : current.listFiles()) {
-            if (file.isDirectory()) {
-                scanForClasses(rootLength, file, p);
-            } else {
-                processFileName(file.getPath().substring(rootLength), p);
+        final File[] files = current.listFiles();
+        if (files != null) {
+            for (final File file : files) {
+                if (file.isDirectory()) {
+                    scanForClasses(rootLength, file, p);
+                } else {
+                    processFileName(file.getPath().substring(rootLength), p);
+                }
             }
         }
     }
diff --git 
a/src/test/java/org/apache/commons/net/ftp/parser/MLSDComparison.java 
b/src/test/java/org/apache/commons/net/ftp/parser/MLSDComparison.java
index 09f0fd9..375e4ed 100644
--- a/src/test/java/org/apache/commons/net/ftp/parser/MLSDComparison.java
+++ b/src/test/java/org/apache/commons/net/ftp/parser/MLSDComparison.java
@@ -60,22 +60,25 @@ public class MLSDComparison {
             }
 
         };
-        for (final File mlsd : path.listFiles(filter)) {
-            System.out.println(mlsd);
-            FTPListParseEngine engine = new 
FTPListParseEngine(MLSxEntryParser.getInstance());
-            try (final InputStream is = new FileInputStream(mlsd)) {
-                engine.readServerList(is, FTP.DEFAULT_CONTROL_ENCODING);
-            }
-            final FTPFile[] mlsds = engine.getFiles(FTPFileFilters.ALL);
-            final File listFile = new File(mlsd.getParentFile(), 
mlsd.getName().replace("_mlsd", "_list"));
-            try (final InputStream inputStream = new 
FileInputStream(listFile)) {
-                final FTPClientConfig cfg = new FTPClientConfig();
-                cfg.setServerTimeZoneId("GMT");
-                final UnixFTPEntryParser parser = new UnixFTPEntryParser(cfg);
-                engine = new FTPListParseEngine(parser);
-                engine.readServerList(inputStream, 
FTP.DEFAULT_CONTROL_ENCODING);
-                final FTPFile[] lists = engine.getFiles(FTPFileFilters.ALL);
-                compareSortedLists(mlsds, lists);
+        final File[] files = path.listFiles(filter);
+        if (files != null) {
+            for (final File mlsd : files) {
+                System.out.println(mlsd);
+                FTPListParseEngine engine = new 
FTPListParseEngine(MLSxEntryParser.getInstance());
+                try (final InputStream is = new FileInputStream(mlsd)) {
+                    engine.readServerList(is, FTP.DEFAULT_CONTROL_ENCODING);
+                }
+                final FTPFile[] mlsds = engine.getFiles(FTPFileFilters.ALL);
+                final File listFile = new File(mlsd.getParentFile(), 
mlsd.getName().replace("_mlsd", "_list"));
+                try (final InputStream inputStream = new 
FileInputStream(listFile)) {
+                    final FTPClientConfig cfg = new FTPClientConfig();
+                    cfg.setServerTimeZoneId("GMT");
+                    final UnixFTPEntryParser parser = new 
UnixFTPEntryParser(cfg);
+                    engine = new FTPListParseEngine(parser);
+                    engine.readServerList(inputStream, 
FTP.DEFAULT_CONTROL_ENCODING);
+                    final FTPFile[] lists = 
engine.getFiles(FTPFileFilters.ALL);
+                    compareSortedLists(mlsds, lists);
+                }
             }
         }
     }

Reply via email to