This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 222569

Summary: Encoding in package names
Product: platform Reporter: s0uky
Component: JDK ProblemsAssignee: Tomas Zezula <tzezula>
Status: RESOLVED WONTFIX    
Severity: normal CC: sworisbreathing
Priority: P3    
Version: 7.2.1   
Hardware: Macintosh   
OS: Mac OS X   
URL: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8003228
Issue Type: DEFECT Exception Reporter:
Attachments: Encoding error in names

Description s0uky 2012-11-22 01:37:52 UTC
Created attachment 128234 [details]
Encoding error in names

I want report an encoding bug in package or class name. 
I use Czech language. My OS X locale is UTF8, Netbeans is in UTF8 too.
Problem for me is in czech characters. If I use name for package or class, for example "testžýáíé" result is "test?????".

See attached picture. 
On the right side is ZIP archive with packages and classes. In left side is copied packages and classes to new project. Check the names.

In Netbeans version 6.9.1 was everything OK.
Comment 1 Tomas Zezula 2012-11-22 09:06:51 UTC
>In Netbeans version 6.9.1 was everything OK.
Same JDK and Mac OS X version?
Originally the default charset on Mac was MacRoman which had been changed in Lion or Mountain Lion.
Does it work with MacRoman encoding?
Comment 2 Tomas Zezula 2012-11-22 09:15:54 UTC
I've forgot what JDK version?
Comment 3 s0uky 2012-11-22 10:25:17 UTC
(In reply to comment #2)
> I've forgot what JDK version?

I forgot say about bug - code in class have good encoding, but not in class / package name.

If I use MacRoman encoding everything have bad encoding - names and code inside classes too.

My system:
Product Version: NetBeans IDE 7.2.1 (Build 201210100934)
Java: 1.7.0_07; Java HotSpot(TM) 64-Bit Server VM 23.3-b01
System: Mac OS X version 10.8.2 running on x86_64; US-ASCII; cs_CZ (nb)
User directory: /Users/s0uky/Library/Application Support/NetBeans/7.2.1
Cache directory: /Users/s0uky/Library/Caches/NetBeans/7.2.1

Now I have US-ASCII encoding, but if try -J-Dfile.encoding=UTF-8 in config, nothig happens.
Comment 4 s0uky 2012-11-23 10:07:23 UTC
(In reply to comment #1)
> >In Netbeans version 6.9.1 was everything OK.
> Same JDK and Mac OS X version?

On 6.9.1 I must USE JDK6, because JDK7 is not supported. 
I think JDK version is not important in this bug.
Comment 5 Tomas Zezula 2013-01-11 14:36:35 UTC
In fact it's an issue  in between OS X and  Java.
The issue is reproduceable on both Apple JDK 6 and ORACLE JDK 7.
It can be easily reproduced by simple Java program:


package testencoding;
import java.io.File;
public class TestEncoding {
    public static void main(String[] args) {
        final File f = new File (new File (System.getProperty("user.dir")),"data");
        f.mkdir();
        final File c = new File (f,"testžýáíé");
        c.mkdir();
        for (File x : f.listFiles()) {
            System.out.println(x.getAbsolutePath());
        }        
    }
}


The folder (file) created on disk has illegally encoded characters.
The fix is quite easy but quite hard to find out.
All you need is to do:

export LC_CTYPE=UTF-8

in shell you start the netbeans in or in ~/.profile or in ${NB}/etc/netbeans.conf.
Another possibility is in Terminal settings check Advanced/Set Locale Environment variables.... but
it will probably work only when the NB is started from terminal.

In case when LC_CTYPE is missing the sun.jnu.encoding is MacRoman not UTF-8, when you set the LC_CTYPE the sun.jnu.encoding becomes UTF-8. The sun.jnu.encoding represents the platform encoding for the JVM. Unlike file.encoding which affects how the content of text files is encoded by default. The file.encoding may differ from the sun.jnu.encoding as in your case. There valid JVM use case where sun.jnu.encoding != file.encoding especially when file.encoding is explicitly given to JVM.

If you are interested you can look at:
jdk/src/solaris/native/java/lang/java_props_md.c
jdk/src/share/native/common/jni_util.c
jdk/src/solaris/native/java/lang/java_props_macosx.c

and:

https://developer.apple.com/library/mac/#documentation/CoreFoundation/Reference/CFLocaleRef/Reference/reference.html
Comment 6 Tomas Zezula 2013-01-11 15:00:33 UTC
In the JDK 8 the sun.jnu.encoding is correctly set to UTF-8.
JDK issue http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8003228
Comment 7 Tomas Zezula 2013-02-05 10:35:29 UTC
*** Bug 225743 has been marked as a duplicate of this bug. ***