JDK-6277100 : Java default file encoding not taking precedence as default charset encoding when -Duser.* set
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio.charsets
  • Affected Version: 1.4.2_08
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_9
  • CPU: sparc
  • Submitted: 2005-05-27
  • Updated: 2014-10-24
  • Resolved: 2005-05-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.2_08Resolved
Related Reports
Duplicate :  
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

###@###.### 2005-05-27 09:13:37 GMT

Comments
EVALUATION This is not a bug. Please see the evaluation and comments in 4163515. ###@###.### 2005-05-27 17:59:14 GMT
27-05-2005

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 ###@###.### 2005-05-27 09:25:35 GMT
27-05-2005

SUGGESTED FIX ###@###.### 2005-05-27 09:25:34 GMT
27-05-2005