Solved

File misbehaving with Unicode Surrogate Pairs

Posted on 2009-05-08
11
324 Views
Last Modified: 2012-05-06
I have two scenarios:

#1) I can create a file using a different program (not java) and java is unable to read this file
#2) Java can't create a file using a unicode surrogate pair.

I've tried this on solaris and Macosx, using HFS and NFS, both local and over TCP.

this was saved properly in UTF-8 and was executed using -Dfile.encoding="UTF-8"

See the file below, in one I use the actual char, in the other I use the encoded version (both should work out to the same UTF8 String).

Why can't java open or create this file? What am I doing wrong? I *know* the filesystem can deal with the file, since I can create it using a different mechanism.
public class FreakinUTF8{

    public static void main(String args[]){

      String tmp = "/tmp/\uD85C\uDD0D.txt";

      //String tmp = "/tmp/\
.txt";//this is the encoded char.

      File newFile = new File(tmp);

      boolean b = false;

      try {

        b = newFile.createNewFile();

        System.out.println("Created:"+b+" and exists:"+newFile.exists());

      } catch (IOException e) {

        e.printStackTrace();

      }
 

    }

  }

Open in new window

0
Comment
Question by:kylar
  • 4
  • 3
  • 3
11 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 24339757
It's OK for me. See below:
goose@seegobin:/tmp$ ll

total 68

drwxrwxrwt  9 root  root  4096 2009-05-08 21:04 .

drwxr-xr-x 22 root  root  4096 2009-04-13 09:09 ..

-rw-r--r--  1 goose goose  973 2009-05-08 20:59 FreakinUTF8.class

-rw-r--r--  1 goose goose  421 2009-05-08 20:59 FreakinUTF8.java

drwx------  3 goose goose 4096 2009-05-08 17:12 gconfd-goose

drwxr-xr-x  2 goose goose 4096 2009-05-08 21:01 hsperfdata_goose

drwxrwxrwt  2 root  root  4096 2009-05-08 17:12 .ICE-unix

drwx------  2 goose goose 4096 2009-05-08 17:12 orbit-goose

drwx------  2 goose goose 4096 2009-05-08 19:16 plugtmp

-rw-------  1 goose goose  981 2009-05-08 21:04 purple3GGPTU

-rw-------  1 goose goose  106 2009-05-08 17:12 serverauth.iRnPqXRSMp

drwx------  2 goose goose 4096 2009-05-08 17:12 ssh-UrGtFI2893

-r--r--r--  1 root  root    11 2009-05-08 17:12 .X0-lock

drwxrwxrwt  2 root  root  4096 2009-05-08 17:12 .X11-unix

-rw-------  1 goose goose  207 2009-05-08 17:12 .xfsm-ICE-H69RTU

goose@seegobin:/tmp$ java FreakinUTF8

Created:true and exists:true

goose@seegobin:/tmp$ ll

total 68

drwxrwxrwt  9 root  root  4096 2009-05-08 21:05 .

drwxr-xr-x 22 root  root  4096 2009-04-13 09:09 ..

-rw-r--r--  1 goose goose  973 2009-05-08 20:59 FreakinUTF8.class

-rw-r--r--  1 goose goose  421 2009-05-08 20:59 FreakinUTF8.java

drwx------  3 goose goose 4096 2009-05-08 17:12 gconfd-goose

drwxr-xr-x  2 goose goose 4096 2009-05-08 21:05 hsperfdata_goose

drwxrwxrwt  2 root  root  4096 2009-05-08 17:12 .ICE-unix

drwx------  2 goose goose 4096 2009-05-08 17:12 orbit-goose

drwx------  2 goose goose 4096 2009-05-08 19:16 plugtmp

-rw-------  1 goose goose  981 2009-05-08 21:04 purple3GGPTU

-rw-------  1 goose goose  106 2009-05-08 17:12 serverauth.iRnPqXRSMp

drwx------  2 goose goose 4096 2009-05-08 17:12 ssh-UrGtFI2893

-rw-r--r--  1 goose goose    0 2009-05-08 21:05 \
.txt

-r--r--r--  1 root  root    11 2009-05-08 17:12 .X0-lock

drwxrwxrwt  2 root  root  4096 2009-05-08 17:12 .X11-unix

-rw-------  1 goose goose  207 2009-05-08 17:12 .xfsm-ICE-H69RTU

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24339766
Unfortunately the character doesn't work on this site, but i can tell you it's there
0
 
LVL 4

Author Comment

by:kylar
ID: 24339904
What kind of box are you running it on? What kind of storage?
0
 
LVL 92

Expert Comment

by:objects
ID: 24342129
what version of java are you using? Have you tried latest?

0
 
LVL 92

Expert Comment

by:objects
ID: 24342147
it used to be a problem but was fixed ages ago

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4845710

what result exactly are you getting?

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:kylar
ID: 24366991
I've tried with 1.5 and 1.6 on Solaris & MacOSX. I get this result on:

MacOSX when using locally attached HFS storage
MacOSX when using remote NFS storage
Solaris when using remote NFS storage

but not Solaris using local NFS storage.

I get an IOException when I run it:

Exception in thread "main" java.io.IOException: No such file or directory
      at java.io.UnixFileSystem.createFileExclusively(Native Method)
      at java.io.File.createNewFile(File.java:883)
      at UTF8Test.<init>(UTF8Test.java:20)
      at SymlinkTest.main(SymlinkTest.java:3)

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24367487
Do you get the same errors *outside Java*
0
 
LVL 92

Expert Comment

by:objects
ID: 24370115
I'd suggest raising a bug with Sun

0
 
LVL 4

Accepted Solution

by:
kylar earned 0 total points
ID: 24830160
I've raised a bug with Apple, since they are the ones who do the MacOSX jdk.
0
 
LVL 92

Expert Comment

by:objects
ID: 24830220
sorry yes apple :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
netstat -ano | find "8000" and taskkill /f /pid 2984 3 38
map related example 6 38
xampp tool 12 28
MySQL  on Tomcat 8 30
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now