3

It seems that the following file.listFiles() is broken on OpenJDK 7 on OS X.

This code snippet will print "This file has a euro symbol...does't exist".

    final String pathname = System.getProperty("user.home") + 
          "/folderThatContainsAFileWithTheEuroSymbol/";
    final File folder = new File(pathname);
    for (File file : folder.listFiles()) {
        if (!file.exists()) {
            System.out.println("This file has a euro symbol in its name, it exists and yet file.exists says it doesn't exist");
        }
    }

It seems to be a known problem.

I'm looking for a work-around. This is for consumer software, so ideally the solution would involve no low-level chicanery on the part of the end user. I'm hoping there is a solution which solely involves a small code change on my behalf.

There is a suggested solution here, but that involves setting a command line environment variable, which is beyond the realm of many of my users.

Any ideas?

Community
  • 1
  • 1
Steve McLeod
  • 51,737
  • 47
  • 128
  • 184
  • How do your users launch the application? From your question, I assume that you do not deploy a launch wrapper script during installation/upgrade, where you can simply set the environment variable? Do you have some kind of installer which users execute when installing/upgrading? – Andreas Fester Dec 07 '12 at 11:37
  • I use Apple's JarBundler, which has an Info.plist file. Does a solution lie in there? – Steve McLeod Dec 07 '12 at 11:41
  • My thinking was whether you can specify an environment variable during startup, but this seems not possible with Info.plist. Setting a property would work, but the relevant one (sun.jnu.encoding) can not be set on the command line since it is derived from the LC_ environment variables. One of the links in your question mention that the bug seems to be specific to the old IO API, while it seems to work with the NIO APIs - did you try whether converting your code to use NIO (similar to http://pastebin.com/wWkXBJpK) fixes the issue? – Andreas Fester Dec 10 '12 at 20:32

1 Answers1

0

This is fixed in the Java Development Kit 7 Update 10 (JDK 7u10).

Steve McLeod
  • 51,737
  • 47
  • 128
  • 184