2828import java .net .URLConnection ;
2929import java .util .Arrays ;
3030import java .util .Collections ;
31+ import java .util .Comparator ;
3132import java .util .Enumeration ;
3233import java .util .LinkedHashSet ;
3334import java .util .Set ;
@@ -783,15 +784,7 @@ protected void doRetrieveMatchingFiles(String fullPattern, File dir, Set<File> r
783784 logger .debug ("Searching directory [" + dir .getAbsolutePath () +
784785 "] for files matching pattern [" + fullPattern + "]" );
785786 }
786- File [] dirContents = dir .listFiles ();
787- if (dirContents == null ) {
788- if (logger .isWarnEnabled ()) {
789- logger .warn ("Could not retrieve contents of directory [" + dir .getAbsolutePath () + "]" );
790- }
791- return ;
792- }
793- Arrays .sort (dirContents );
794- for (File content : dirContents ) {
787+ for (File content : listDirectory (dir )) {
795788 String currPath = StringUtils .replace (content .getAbsolutePath (), File .separator , "/" );
796789 if (content .isDirectory () && getPathMatcher ().matchStart (fullPattern , currPath + "/" )) {
797790 if (!content .canRead ()) {
@@ -810,6 +803,25 @@ protected void doRetrieveMatchingFiles(String fullPattern, File dir, Set<File> r
810803 }
811804 }
812805
806+ /**
807+ * Determine a sorted list of files in the given directory.
808+ * @param dir the directory to introspect
809+ * @return the sorted list of files (by default in alphabetical order)
810+ * @since 5.1
811+ * @see File#listFiles()
812+ */
813+ protected File [] listDirectory (File dir ) {
814+ File [] files = dir .listFiles ();
815+ if (files == null ) {
816+ if (logger .isWarnEnabled ()) {
817+ logger .warn ("Could not retrieve contents of directory [" + dir .getAbsolutePath () + "]" );
818+ }
819+ return new File [0 ];
820+ }
821+ Arrays .sort (files , Comparator .comparing (File ::getName ));
822+ return files ;
823+ }
824+
813825
814826 /**
815827 * Inner delegate class, avoiding a hard JBoss VFS API dependency at runtime.
0 commit comments