Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6954599

java.io.File.isFile() returns false for the files with '.' (dot) as the latest s

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u10
    • core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_19"
      Java(TM) SE Runtime Environment (build 1.6.0_19-b04)
      Java HotSpot(TM) Client VM (build 16.2-b04, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      We have two files in "test" directory.

      ======DIR=======
      C:\test>dir
       Volume in drive C has no label.
       Volume Serial Number is 941B-42F4

       Directory of C:\test

      05/21/2010 02:47 PM <DIR> .
      05/21/2010 02:47 PM <DIR> ..
      05/21/2010 02:44 PM 0 a_file
      05/21/2010 02:44 PM 0 not_a_file.
                     2 File(s) 0 bytes
                     2 Dir(s) 17,429,995,520 bytes free
      ======DIR=======

      Following code shows that java determines "a_file" as a file, but "not_a_file." as not a file.
      The reason is that file "not_a_file." has '.' (dot) as the latest symbol.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      File a_file isFile() = true
      File not_a_file. isFile() = true
      ACTUAL -
      File a_file isFile() = true
      File not_a_file. isFile() = false

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package test;

      import java.io.File;
      import java.io.IOException;

      public class FileIsNotAFileTest {
          public static void main(String[] args) throws IOException {
              File dir = new File("./test");
              for (File file : dir.listFiles()) {
                  System.out.print("File "+file.getName());
                  System.out.println(" isFile() = "+file.isFile());
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use !isDirectory() to test if file is really file

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: