You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by od...@apache.org on 2010/04/26 18:31:15 UTC
svn commit: r938116 -
/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java
Author: odeakin
Date: Mon Apr 26 16:31:15 2010
New Revision: 938116
URL: http://svn.apache.org/viewvc?rev=938116&view=rev
Log:
Make sure that we use a consistent encoding across platforms, as getBytes() and String(byte[]) use the default platform encoding if it is not specified which causes these calls to fail on, for example, z/OS.
Modified:
harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java
Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java?rev=938116&r1=938115&r2=938116&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java Mon Apr 26 16:31:15 2010
@@ -16,6 +16,7 @@
package org.apache.harmony.luni.platform;
+import java.io.UnsupportedEncodingException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -63,11 +64,16 @@ public class Environment {
* @return the value of the environment variable specified
*/
public static String getenv(String name) {
- byte[] env = getEnvByName(name.getBytes());
- if (null == env) {
- return null;
- }
- return new String(env);
+ try {
+ byte[] env = getEnvByName(name.getBytes("UTF-8"));
+ if (null == env) {
+ return null;
+ }
+ return new String(env, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ // UTF-8 should always be supported so this should not be reached
+ throw new RuntimeException(e);
+ }
}
public static class EnvironmentMap extends HashMap<String, String> {
Re: svn commit: r938116 - /harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java
Posted by Oliver Deakin <ol...@googlemail.com>.
On 30/04/2010 05:33, Nathan Beyer wrote:
> On Mon, Apr 26, 2010 at 11:31 AM,<od...@apache.org> wrote:
>
>> Author: odeakin
>> Date: Mon Apr 26 16:31:15 2010
>> New Revision: 938116
>>
>> URL: http://svn.apache.org/viewvc?rev=938116&view=rev
>> Log:
>> Make sure that we use a consistent encoding across platforms, as getBytes() and String(byte[]) use the default platform encoding if it is not specified which causes these calls to fail on, for example, z/OS.
>>
>> Modified:
>> harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java
>>
>> Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java
>> URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java?rev=938116&r1=938115&r2=938116&view=diff
>> ==============================================================================
>> --- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java (original)
>> +++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java Mon Apr 26 16:31:15 2010
>> @@ -16,6 +16,7 @@
>>
>> package org.apache.harmony.luni.platform;
>>
>> +import java.io.UnsupportedEncodingException;
>> import java.util.Collections;
>> import java.util.HashMap;
>> import java.util.Map;
>> @@ -63,11 +64,16 @@ public class Environment {
>> * @return the value of the environment variable specified
>> */
>> public static String getenv(String name) {
>> - byte[] env = getEnvByName(name.getBytes());
>> - if (null == env) {
>> - return null;
>> - }
>> - return new String(env);
>> + try {
>> + byte[] env = getEnvByName(name.getBytes("UTF-8"));
>> + if (null == env) {
>> + return null;
>> + }
>> + return new String(env, "UTF-8");
>> + } catch (UnsupportedEncodingException e) {
>> + // UTF-8 should always be supported so this should not be reached
>> + throw new RuntimeException(e);
>>
> Any objections to using the 'throw new AssertionError(e)' idiom in
> this case instead of RuntimeException?
>
None at all, I just didn't think of it at the time of the commit.
Replaced RuntimeException with AssertionError at r939629.
Regards,
Oliver
>
>> + }
>> }
>>
>> public static class EnvironmentMap extends HashMap<String, String> {
>>
>>
>>
>>
>
--
Oliver Deakin
Unless stated otherwise above:
IBM United Kingdom Limited - Registered in England and Wales with number 741598.
Registered office: PO Box 41, North Harbour, Portsmouth, Hampshire PO6 3AU
Re: svn commit: r938116 - /harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java
Posted by Nathan Beyer <nd...@apache.org>.
On Mon, Apr 26, 2010 at 11:31 AM, <od...@apache.org> wrote:
> Author: odeakin
> Date: Mon Apr 26 16:31:15 2010
> New Revision: 938116
>
> URL: http://svn.apache.org/viewvc?rev=938116&view=rev
> Log:
> Make sure that we use a consistent encoding across platforms, as getBytes() and String(byte[]) use the default platform encoding if it is not specified which causes these calls to fail on, for example, z/OS.
>
> Modified:
> harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java
>
> Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java
> URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java?rev=938116&r1=938115&r2=938116&view=diff
> ==============================================================================
> --- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java (original)
> +++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/org/apache/harmony/luni/platform/Environment.java Mon Apr 26 16:31:15 2010
> @@ -16,6 +16,7 @@
>
> package org.apache.harmony.luni.platform;
>
> +import java.io.UnsupportedEncodingException;
> import java.util.Collections;
> import java.util.HashMap;
> import java.util.Map;
> @@ -63,11 +64,16 @@ public class Environment {
> * @return the value of the environment variable specified
> */
> public static String getenv(String name) {
> - byte[] env = getEnvByName(name.getBytes());
> - if (null == env) {
> - return null;
> - }
> - return new String(env);
> + try {
> + byte[] env = getEnvByName(name.getBytes("UTF-8"));
> + if (null == env) {
> + return null;
> + }
> + return new String(env, "UTF-8");
> + } catch (UnsupportedEncodingException e) {
> + // UTF-8 should always be supported so this should not be reached
> + throw new RuntimeException(e);
Any objections to using the 'throw new AssertionError(e)' idiom in
this case instead of RuntimeException?
> + }
> }
>
> public static class EnvironmentMap extends HashMap<String, String> {
>
>
>