@@ -254,32 +254,32 @@ public void addListener(final FileAlterationListener listener) {
254254 *
255255 * @param parent The parent entry.
256256 * @param previous The original list of files.
257- * @param files The current list of files.
257+ * @param current The current list of files.
258258 */
259- private void checkAndFire (final FileEntry parent , final FileEntry [] previous , final File [] files ) {
259+ private void checkAndFire (final FileEntry parent , final FileEntry [] previous , final File [] current ) {
260260 int c = 0 ;
261- final FileEntry [] current = files .length > 0 ? new FileEntry [files .length ] : FileEntry .EMPTY_FILE_ENTRY_ARRAY ;
261+ final FileEntry [] actual = current .length > 0 ? new FileEntry [current .length ] : FileEntry .EMPTY_FILE_ENTRY_ARRAY ;
262262 for (final FileEntry entry : previous ) {
263- while (c < files .length && comparator .compare (entry .getFile (), files [c ]) > 0 ) {
264- current [c ] = createFileEntry (parent , files [c ]);
265- fireOnCreate (current [c ]);
263+ while (c < current .length && comparator .compare (entry .getFile (), current [c ]) > 0 ) {
264+ actual [c ] = createFileEntry (parent , current [c ]);
265+ fireOnCreate (actual [c ]);
266266 c ++;
267267 }
268- if (c < files .length && comparator .compare (entry .getFile (), files [c ]) == 0 ) {
269- fireOnChange (entry , files [c ]);
270- checkAndFire (entry , entry .getChildren (), listFiles (files [c ]));
271- current [c ] = entry ;
268+ if (c < current .length && comparator .compare (entry .getFile (), current [c ]) == 0 ) {
269+ fireOnChange (entry , current [c ]);
270+ checkAndFire (entry , entry .getChildren (), listFiles (current [c ]));
271+ actual [c ] = entry ;
272272 c ++;
273273 } else {
274274 checkAndFire (entry , entry .getChildren (), FileUtils .EMPTY_FILE_ARRAY );
275275 fireOnDelete (entry );
276276 }
277277 }
278- for (; c < files .length ; c ++) {
279- current [c ] = createFileEntry (parent , files [c ]);
280- fireOnCreate (current [c ]);
278+ for (; c < current .length ; c ++) {
279+ actual [c ] = createFileEntry (parent , current [c ]);
280+ fireOnCreate (actual [c ]);
281281 }
282- parent .setChildren (current );
282+ parent .setChildren (actual );
283283 }
284284
285285 /**
@@ -436,17 +436,7 @@ private FileEntry[] listFileEntries(final File file, final FileEntry entry) {
436436 * @return the directory contents or a zero length array if the empty or the file is not a directory
437437 */
438438 private File [] listFiles (final File directory ) {
439- File [] children = null ;
440- if (directory .isDirectory ()) {
441- children = directory .listFiles (fileFilter );
442- }
443- if (children == null ) {
444- children = FileUtils .EMPTY_FILE_ARRAY ;
445- }
446- if (children .length > 1 ) {
447- Arrays .sort (children , comparator );
448- }
449- return children ;
439+ return directory .isDirectory () ? sort (directory .listFiles (fileFilter )) : FileUtils .EMPTY_FILE_ARRAY ;
450440 }
451441
452442 /**
@@ -460,6 +450,16 @@ public void removeListener(final FileAlterationListener listener) {
460450 }
461451 }
462452
453+ private File [] sort (final File [] files ) {
454+ if (files == null ) {
455+ return FileUtils .EMPTY_FILE_ARRAY ;
456+ }
457+ if (files .length > 1 ) {
458+ Arrays .sort (files , comparator );
459+ }
460+ return files ;
461+ }
462+
463463 /**
464464 * Returns a String representation of this observer.
465465 *
0 commit comments