JDK-5052844 : file.encoding parameter ignored on Intel Linux
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2004-05-25
  • Updated: 2004-05-26
  • Resolved: 2004-05-26
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 05/25/2004


FULL PRODUCT VERSION :
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Red Hat, Linux 2.4.2 on Intel

A DESCRIPTION OF THE PROBLEM :
Specifing the -Dfile.encoding value on the Java command line does not set the default encoding used the the IO libraries on Linux. It works fine on Windows and on Mac OS X.

The parameter is passed into the runtime system with no problem but the IO libriaries are not using it. The IO libraries appear to be using the file encoding part of the LANG enviroment variable instead.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the code below on a linux machine. Try with something like

java -Dfile.enocoding=US-ASCII FileEncodingTest

Set the encoding to be what ever you like. The actual value used will not change.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The actual default encoding using by the streams library should be of the same type as that of the file.encoding parameter, so long as that parameter contains a valid encoding.
ACTUAL -
The value printed out as the "actual value" is always the LANG environment variable encoding value. The file.encoding parameter is passed in, but ignored.

This works as expected on Windows and on Mac OS X.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;

public class FileEncodingTest {
    public static void main(String[] args) {
        String property = System.getProperty("file.encoding");
        String actual = new OutputStreamWriter(
                       new ByteArrayOutputStream()).getEncoding();
        System.out.println("property=" + property + ", actual=" + actual);
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Change the LANG enviroment variable.
(Incident Review ID: 274951) 
======================================================================