JDK-6328466 : (process) (6317399): encoding used for environment variables on Unix
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 5.0u4
  • Priority: P2
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2005-09-24
  • Updated: 2010-04-03
  • Resolved: 2006-02-01
Related Reports
Relates :  
Description
Please first read Comments section here and in 6317399.

In java/lang/ProcessEnvironment.java (5.0u4):

// wrong line 148
	    return new Variable(str, str.getBytes());
// correction:
	    try
	    {
		return new Variable(str, str.getBytes("ISO-8859-1"));
	    }
	    catch (UnsupportedEncodingException ex)
	    {
		return null;
	    }
// wrong line 157
	    return new Variable(new String(bytes), bytes);
// correction:
	    try
	    {
		return new Variable(new String(bytes,"ISO-8859-1"), bytes);
	    }
	    catch (UnsupportedEncodingException ex)
	    {
		return null;
	    }
// wrong line 181
	    return new Value(str, str.getBytes());
// correction:
	    try
	    {
		return new Value(str, str.getBytes("ISO-8859-1"));
	    }
	    catch (UnsupportedEncodingException ex)
	    {
		return null;
	    }
// wrong line 190
	    return new Value(new String(bytes), bytes);
// correction:
	    try
	    {
		return new Value(new String(bytes,"ISO-8859-1"), bytes);
	    }
	    catch (UnsupportedEncodingException ex)
	    {
		return null;
	    }


In java/lang/ProcessImpl.java (5.0u4):

// wrong line 28
	byte[] bytes = s.getBytes();
// correction:
	byte[] bytes = null;
	try {
	    bytes = s.getBytes("ISO-8859-1");
	}
	catch (java.io.UnsupportedEncodingException ex)
	{}
// wrong line 51
	    args[i] = cmdarray[i+1].getBytes();
// correction:
	    try {
		args[i] = cmdarray[i+1].getBytes("ISO-8859-1");
	    }
	    catch (java.io.UnsupportedEncodingException ex)
	    {}

Comments
EVALUATION See comments for 6317399. It is quite intentional that environment variables use the system default encoding, just like filenames. Use of any specific encoding like Latin-1 is incorrect in non-Latin-1 locales. The suggested change clearly cannot be made. When environment variables were designed, giving access to the underlying OS representation (byte array on Unix) was considered and rejected, since corresponding access does not exist for filenames. Perhaps some other change can be made, but the suggested fix must be rejected. We also don't have a test case, so we can't know exactly what the user's problem is. Please reopen if I've missed something
01-02-2006

SUGGESTED FIX See Description.
24-09-2005