Commons IO
  1. Commons IO
  2. IO-16

DirectoryFileFilter does not work, the AbstractFileFilter bug

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: Windows XP
      Platform: PC

      Description

      Env: Java 1.4.2, commons-io-1.0.jar, Win XP

      The AbstractFileFilter's FilenameFilter's accept(File, String) method
      implementation constructs the fileName/File (it passes to accept(File))
      wrongly - please see below. This causes the DirectoryFileFilter (in example, I
      did not have time to check out the other AbstractFileFilter implementations)
      failure since it's FileFilter implementation receives the incorrect
      filename/File.

      Note I stumbled into this in Win Env. and really don't know how it works in
      other platforms.

      v1.0 code:
      public boolean accept(File dir, String name)

      { String filename = dir.getName() + File.separator + name; return accept(new File(filename)); }

      correct code should be:
      public boolean accept(File dir, String name)

      { String filename = dir.getPath() + File.separator + name; return accept(new File(filename)); }

        Activity

        Hide
        Martin Cooper added a comment -

        Fixed in the 20041025 nightly build. Instead of doing the work ourselves, I
        used "new File(dir, name)" instead.

        Show
        Martin Cooper added a comment - Fixed in the 20041025 nightly build. Instead of doing the work ourselves, I used "new File(dir, name)" instead.

          People

          • Assignee:
            Unassigned
            Reporter:
            Nebojsa Perunicic
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development