Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6277100
Votes 0
Synopsis Java default file encoding not taking precedence as default charset encoding when -Duser.* set
Category java:char_encodings
Reported Against
Release Fixed
State 11-Closed, duplicate of 4163515, bug
Priority: 4-Low
Related Bugs
Submit Date 27-MAY-2005
Description
======
NOTE: 
=====
- Must be run in Japanese Locale as Eg

   LANG=ja
   LC_CTYPE="ja"
   LC_NUMERIC="ja"
   LC_TIME="ja"
   LC_COLLATE="ja"
   LC_MONETARY="ja"
   LC_MESSAGES="ja"
   LC_ALL=

- Run the below test on JDK 1.4.2.x, 1.5.x
  (1.5.x is is the reference expected)
- java -Dfile.encoding=MS932 Test2 
  Expected: See that the default encoding is MS932
- java -Dfile.encoding=MS932 -Duser.language=ja Test2
   Actual: You get EUC_JP_SOLARIS !!! not MS932

========
Problem 
========
So the problem is that when program that is progranmmed to
assume to have a certain file.encoding and that Java program
is not code to open with InputStreamReader(fs,charset) will
have problem.


TEST Case
==========
import java.util.*;
import java.io.*;

public class Test2 {
    public static void main(String args[]) {
        System.out.println("os: "+System.getProperty("os.name"));
        System.out.println("Locale: "+java.util.Locale.getDefault());
        System.out.println("Lang: "+
               java.util.Locale.getDefault().getLanguage());
        System.out.println("FileEnc: "+
             System.getProperty("file.encoding"));
        System.out.println("UserLang: "+
             System.getProperty("user.language"));
        System.out.println("DefEncName: "+
             sun.io.Converters.getDefaultEncodingName());
        try {
              String[] encode = { "", "UTF-8", "EUC-JP", "Shift_JIS", "MS932" };
           File fileDir = new File("./file");
           File[] files = fileDir.listFiles();
           for (int i = 0; i < files.length; i++) {
               for (int j = 0; j < encode.length; j++) {
                BufferedReader br = null;
                InputStreamReader isr = null;
                if (encode[j] == "") {
                        isr = new InputStreamReader(new
                              FileInputStream(files[i]));
                } else {
                        isr = new InputStreamReader(
                            new FileInputStream(files[i]), encode[j]);
                }
                String enc = isr.getEncoding();
                System.out.print("File=" + files[i]);
                System.out.print(" enc[]=" + encode[j]);
                System.out.println(" isr.getEncoding()=" + enc);
              }
            }
        } catch (Exception e) { e.printStackTrace(); };
    }
}

Output JDK 1.4.2_08
os: SunOS
Locale: en_US
Lang: en
FileEnc: MS932
UserLang: en
DefEncName: eucJP-open --> This is  used by InputStreamReader....

==========
NOTE
==========
This works fine in JDK 1.5.0_02 so that means some backport

chee-  xxxxx@xxxxx   2005-05-27 09:13:37 GMT
Work Around
1. Remove -Duser.language

or

2. Use JDk 1.5.x

or

3. Explicitly code to open the file in specific charset
   DO not rely on defaults

or 

Set locale to EN

chee-  xxxxx@xxxxx   2005-05-27 09:25:35 GMT
Evaluation
This is not a bug.  Please see the evaluation and comments in 4163515.

  xxxxx@xxxxx   2005-05-27 17:59:14 GMT
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang