JDK-4733494 : File.exists() fails with unicode characters in name
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: solaris_7
  • CPU: sparc
  • Submitted: 2002-08-19
  • Updated: 2005-11-29
  • Resolved: 2005-11-29
Related Reports
Relates :  
Relates :  
Description
I have a very simply java class that reads the contents of a directory via the File.listFiles() method then iterates 
through that list of files and makes sure that each file in the list exists via the File.exists() method. Simple, eh? 
(source attached)

Well to add a bit of a twist to this, one of the files contained in the directory has a unicode character in it's name.

When I run this class with jdk1.3.1, the class reports that files in the directory exists, as expected.

When I run this class with jdk1.4, the class reports that the file with unicode characters Does NOT exist, even though 
it is present in the File System and appears that Files.listFiles() was able to find it. (see below for output).

What gives???

I have attached a zip which contains the contents of the directory below.

Any insight you have is much appreciated

Eric


sqeel:/home/elambert/testUni/testFile 204 % ls -l
total 10
drwxrwxr-x   3 elambert green        512 Aug  9 00:26 ./
drwxrwxr-x   3 elambert green        512 Aug  9 00:22 ../
drwxrwxr-x   2 elambert green        512 Aug  8 23:07 pkgs00701?/
-rw-rw-r--   1 elambert green        996 Aug  9 00:26 testIt.class
-rw-rw-r--   1 elambert green        596 Aug  9 00:26 testIt.java
sqeel:/home/elambert/testUni/testFile 205 % /net/koori.sfbay/a/v01/jdk/1.3.1/fcs/binaries/solsparc/bin/java -cp . testIt
./pkgs00701? exists
^^^^^^^^^^^^^^^^^^
./testIt.class exists
./testIt.java exists
sqeel:/home/elambert/testUni/testFile 206 % /net/Koori.sfbay/a/v07/jdk/1.4/fcs/binaries/solsparc/bin/java -cp . testIt
./pkgs00701? DOES NOT EXIST
^^^^^^^^^^^^^^^^^^^^^^^^^^^
./testIt.class exists
./testIt.java exists
sqeel:/home/elambert/testUni/testFile 207 %

Comments
EVALUATION This is not a bug in the jdk. The problem is that the program was likely run with a default locale which does not include that character. For example, the default locale on many solaris systems is "C" which corresponds to ISO646 which is 7-bit ASCII. The program will run correctly in the en_US locale since that correponds to the ISO8859-1 character set. Here's the output using the provided test forcing different locales on the command-line: $ LC_ALL=en_US.ISO8859-1 java testIt ./pkgs00701e exists // ("e" == "e'" in shell, not saveable in bug software) ./testIt.class exists ./testIt.java exists $ LC_ALL=C java testIt ./pkgs00701? DOES NOT EXIST ./testIt.class exists ./testIt.java exists In versions of the JDK prior to 1.4, we always forced the "C" locale to the ISO8859-1 character set. In releases 1.4 and later, we support the "C" locale which requires restriction to 7-bit ASCII.
29-11-2005