Uploaded image for project: 'Commons IO'
  1. Commons IO
  2. IO-739

RegexFileFilter matches on path instead of name

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.9.0
    • Fix Version/s: 2.10.0
    • Component/s: Filters
    • Labels:
      None

      Description

      The new RegexFileFilter.accept(Path, BasicFileAttributes) uses the full path for matching. When this filter is used in combination with FileUtils.listFiles(File, IOFileFilter, IOFileFilter), then it will not match anything if a path separator is not part of the pattern.

      The following small program will list all files when used with version 2.8.0 and nothing when used with version 2.9.0:

      import org.apache.commons.io.FileUtils;
      import org.apache.commons.io.filefilter.*;

      import java.io.File;
      import java.util.Collection;

      class ListFilesRegexBug {
         public static void main(String[] args) {
           RegexFileFilter filter = new RegexFileFilter("[^/\\\\]+");
           Collection<File> files = FileUtils.listFiles(new File("."), filter, TrueFileFilter.TRUE);
           for (File f : files) {
             System.out.println(f.getAbsolutePath());
           }
         }
      }

        Attachments

        1. ListFilesRegexBug.java
          0.5 kB
          Hugo Zwaal

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                hzwaal Hugo Zwaal
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: