File.exists() does not work on mac for non-English characters on Java 7 on Mac

Steve Hannah steve at weblite.ca
Tue Jan 22 13:41:37 PST 2013


I just wanted to post my experiences with this bug.  I was having
trouble on OS X in both 1.7.0u11 and 1.7.0u12 with Japanese file names
(File.exists() erroneously returning false).

Scott's fix for LC_CTYPE was the only thing that worked for me.
(tried file.encoding=UTF8, and sun.jnu.encoding=UTF8 to no avail).

As I am deploying to the Mac App store I needed to set this
environment variable using the Info.plist file, and the current
appbundler ant task didn't have an option to set arbitrary keys/values
in the Info.plist, so I modified the appbundler source (I was actually
working off of the infinitekind fork of appbundler at
https://bitbucket.org/infinitekind/appbundler) to automatically set
the LSEnvironment key.

The diff for this change is:

diff -r 563fcd766efe appbundler/src/com/oracle/appbundler/AppBundlerTask.java
--- a/appbundler/src/com/oracle/appbundler/AppBundlerTask.java	Wed Sep
19 17:54:08 2012 +0100
+++ b/appbundler/src/com/oracle/appbundler/AppBundlerTask.java	Tue Jan
22 13:31:11 2013 -0800
@@ -577,7 +577,16 @@

             xout.writeEndElement();
             xout.writeCharacters("\n");
-
+
+            // Write Environment
+            writeKey(xout, "LSEnvironment");
+            xout.writeStartElement(DICT_TAG);
+            xout.writeCharacters("\n");
+            writeKey(xout, "LC_CTYPE");
+            writeString(xout, "UTF-8");
+            xout.writeEndElement();
+            xout.writeCharacters("\n");
+
             // Write options
             writeKey(xout, "JVMOptions");


I'm not working off the trunk, so I don't know if this problem has
actually been resolved... but this workaround works for me.

Just thought I'd share in case it helps someone else along the line.

-Steve



On Wed, Oct 10, 2012 at 8:58 AM, Scott Kovatch <scott.kovatch at oracle.com> wrote:
> We fixed/worked around this in the plugin by setting the environment variable LC_CTYPE to UTF-8. Given that file names are in UTF-8 by default on OS X this seems unnecessary to me, but there you go.
>
> -- Scott K.
>
>
> On Oct 10, 2012, at 4:41 AM, David Kocher <dkocher at sudo.ch> wrote:
>
>> Agust,
>>
>> My workaround is to use NSFFileManager instead (with bridging through JNA or JNI).
>>
>> -- David
>>
>> On 10.10.2012, at 13:16, Thorkelsson <thorkelsson at sidelinesports.com> wrote:
>>
>>> Thanks for this link David.
>>>
>>> I can see that this bug was marked critical for a year ago, but then I don't know what happens. Obviously it's a tough one.
>>>
>>> But just some feedback for all from a company perspective. At the risk of stating the obvious: This bug is really killing us. We can't release a huge upgrade depending on Java 7 (because of use of the JavaFX 2.2) because of this. We've been trying to workaround this bug for more than a week now without success. We just can't believe that this is something that is out in an official Java release. That's why we've been trying everything to find out what could be wrong on our side. But it doesn't seem to be that way (still don't believe it…)
>>>
>>> I can understand that this has slipped by before because Java 7 hasn't been out long for the Mac. But if it is the way that this is in the release, it will start affecting people quickly.
>>>
>>> This doesn't add to the solution, so I will not write more about it. But please, to those who have the influence, do everything you can to get this into the next update. We are here to help with anything regarding testing or reproducing the bug.
>>>
>>> And of course, if anyone has a workaround, it would be greatly appreciated to learn about it!
>>>
>>> Thanks,
>>>
>>> Agust
>>>
>>>
>>> Agust Thorkelsson
>>> Sideline Sports
>>> thorkelsson at sidelinesports.com
>>> www.sidelinesports.com
>>> Mobile: +46 (0) 704 244 359
>>> EU Office: +46 (0) 40 692 7942
>>>
>>>
>>> On 10 okt 2012, at 11:35, David Kocher <dkocher at sudo.ch> wrote:
>>>
>>>> This issue is being discussed in http://java.net/jira/browse/MACOSX_PORT-165. I will attach a test case again for the non believers.
>>>>
>>>> -- David
>>>>
>>>> On 10.10.2012, at 10:53, Alan Bateman <Alan.Bateman at oracle.com> wrote:
>>>>
>>>>> On 09/10/2012 21:21, Þorvaldur Blöndal wrote:
>>>>>> Hi Alan and thanks for the suggestion.
>>>>>>
>>>>>> I downloaded version 1.8.0-ea-b59 and unfortunately it's the same.
>>>>>> And this is not just about the exists()-method. I can't create a FileInputStream or anything like that.
>>>>>> I can also tell you that files with atypical names are not seen at all in JFileChooser. I have to use java.awt.FileDialog. See attached picture.
>>>>>>
>>>>>> Note: I made a mistake when I said in the report that it previously worked in version 7. I meant to say version 6.
>>>>>>
>>>>> I'll bet this is related to your locale, you can print out the value of the file.encoding property?
>>>>>
>>>>> -Alan.
>>>>>
>>>>
>>>
>>
>



-- 
Steve Hannah
Web Lite Solutions Corp.


More information about the macosx-port-dev mailing list