You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Benjamin Bentmann (JIRA)" <ji...@apache.org> on 2008/07/26 15:11:31 UTC
[jira] Created: (EXEC-30) Make environment variables respect casing
rules of platforms
Make environment variables respect casing rules of platforms
------------------------------------------------------------
Key: EXEC-30
URL: https://issues.apache.org/jira/browse/EXEC-30
Project: Commons Exec
Issue Type: Improvement
Affects Versions: 1.0
Environment: Windows
Reporter: Benjamin Bentmann
Priority: Critical
Intro: Environment variables on Windows are case-insensitive (see [ExpandEnvironmentStrings|http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx]). As a little experiment, run the following code snippet on Windows with Java 1.5
{code:java}
System.out.println(System.getenv("PATH"));
System.out.println(System.getenv("path"));
System.out.println(System.getenv("Path"));
System.out.println(System.getenv().get("PATH"));
System.out.println(System.getenv().get("path"));
System.out.println(System.getenv().get("Path"));
{code}
which can for example output
{noformat}
<successfully resolved variable>
<successfully resolved variable>
<successfully resolved variable>
null
null
<successfully resolved variable>{noformat}
IMHO, this is an example of how an API should *not* be designed. The two overloads of {{System.getenv()}} look very similar but behave completely different. Even having this documented, this subtle peculiarity makes Java programming prone to errors that prevent platform-independence.
Commons Exec is currently providing a case-sensitive view of the Windows shell environment. This makes it effectively impossible for client to code to reliably lookup an environment variable without performing further tweaks to the map returned from {{EnvironmentUtil}}. Furthermore, these tweaks would have to be performed only depending on the current OS, so the client code would need to consider platform details. I believe this violates the basic principle of platform-independence intended by Java.
So here my suggestion: Have Commons Exec provide a case-preserving map that obeys the casing rules of the platform for key lookup. This way, the simple code line
{code:java}
EnvironmentUtils.getProcEnvironment().get("PATH")
{code}
will consistently return the specified variable on Windows and Unix.
Just to mention it: An alternative approach might be to have the map always be case-sensitive but normalize variable names to upper-case on case-insensitive platforms.
Regardless how this issue ends, the documentation for {{getProcEnvironment()}} should clearly state how it deals with casing.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (EXEC-30) Make environment variables respect
casing rules of platforms
Posted by "Benjamin Bentmann (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/EXEC-30?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12648648#action_12648648 ]
Benjamin Bentmann commented on EXEC-30:
---------------------------------------
bq. IMHO it is good practice to stick on a casing that works on all target platform instead of implementing workarounds for badly written program.
Just to make sure it's clearly stated: For the code as is, the line
{code}
System.out.println("PATH = " + EnvironmentUtil.getProcEnvironment().get("PATH"));
{code}
usually prints "PATH = null" on Windows (tried with NT, 2K, XP, Vista).
> Make environment variables respect casing rules of platforms
> ------------------------------------------------------------
>
> Key: EXEC-30
> URL: https://issues.apache.org/jira/browse/EXEC-30
> Project: Commons Exec
> Issue Type: Improvement
> Affects Versions: 1.0
> Environment: Windows
> Reporter: Benjamin Bentmann
> Assignee: Siegfried Goeschl
> Priority: Critical
> Fix For: 1.0
>
> Attachments: EXEC-30.patch
>
>
> Intro: Environment variables on Windows are case-insensitive (see [ExpandEnvironmentStrings|http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx]). As a little experiment, run the following code snippet on Windows with Java 1.5
> {code:java}
> System.out.println(System.getenv("PATH"));
> System.out.println(System.getenv("path"));
> System.out.println(System.getenv("Path"));
> System.out.println(System.getenv().get("PATH"));
> System.out.println(System.getenv().get("path"));
> System.out.println(System.getenv().get("Path"));
> {code}
> which can for example output
> {noformat}
> <successfully resolved variable>
> <successfully resolved variable>
> <successfully resolved variable>
> null
> null
> <successfully resolved variable>{noformat}
> IMHO, this is an example of how an API should *not* be designed. The two overloads of {{System.getenv()}} look very similar but behave completely different. Even having this documented, this subtle peculiarity makes Java programming prone to errors that prevent platform-independence.
> Commons Exec is currently providing a case-sensitive view of the Windows shell environment. This makes it effectively impossible for client to code to reliably lookup an environment variable without performing further tweaks to the map returned from {{EnvironmentUtil}}. Furthermore, these tweaks would have to be performed only depending on the current OS, so the client code would need to consider platform details. I believe this violates the basic principle of platform-independence intended by Java.
> So here my suggestion: Have Commons Exec provide a case-preserving map that obeys the casing rules of the platform for key lookup. This way, the simple code line
> {code:java}
> EnvironmentUtils.getProcEnvironment().get("PATH")
> {code}
> will consistently return the specified variable on Windows and Unix.
> Just to mention it: An alternative approach might be to have the map always be case-sensitive but normalize variable names to upper-case on case-insensitive platforms.
> Regardless how this issue ends, the documentation for {{getProcEnvironment()}} should clearly state how it deals with casing.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Reopened: (EXEC-30) Make environment variables respect
casing rules of platforms
Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/EXEC-30?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Siegfried Goeschl reopened EXEC-30:
-----------------------------------
Confirmed, this is an issue - applied the patch but no retest on Window yet.
> Make environment variables respect casing rules of platforms
> ------------------------------------------------------------
>
> Key: EXEC-30
> URL: https://issues.apache.org/jira/browse/EXEC-30
> Project: Commons Exec
> Issue Type: Improvement
> Affects Versions: 1.0
> Environment: Windows
> Reporter: Benjamin Bentmann
> Assignee: Siegfried Goeschl
> Priority: Critical
> Fix For: 1.0
>
> Attachments: EXEC-30.patch
>
>
> Intro: Environment variables on Windows are case-insensitive (see [ExpandEnvironmentStrings|http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx]). As a little experiment, run the following code snippet on Windows with Java 1.5
> {code:java}
> System.out.println(System.getenv("PATH"));
> System.out.println(System.getenv("path"));
> System.out.println(System.getenv("Path"));
> System.out.println(System.getenv().get("PATH"));
> System.out.println(System.getenv().get("path"));
> System.out.println(System.getenv().get("Path"));
> {code}
> which can for example output
> {noformat}
> <successfully resolved variable>
> <successfully resolved variable>
> <successfully resolved variable>
> null
> null
> <successfully resolved variable>{noformat}
> IMHO, this is an example of how an API should *not* be designed. The two overloads of {{System.getenv()}} look very similar but behave completely different. Even having this documented, this subtle peculiarity makes Java programming prone to errors that prevent platform-independence.
> Commons Exec is currently providing a case-sensitive view of the Windows shell environment. This makes it effectively impossible for client to code to reliably lookup an environment variable without performing further tweaks to the map returned from {{EnvironmentUtil}}. Furthermore, these tweaks would have to be performed only depending on the current OS, so the client code would need to consider platform details. I believe this violates the basic principle of platform-independence intended by Java.
> So here my suggestion: Have Commons Exec provide a case-preserving map that obeys the casing rules of the platform for key lookup. This way, the simple code line
> {code:java}
> EnvironmentUtils.getProcEnvironment().get("PATH")
> {code}
> will consistently return the specified variable on Windows and Unix.
> Just to mention it: An alternative approach might be to have the map always be case-sensitive but normalize variable names to upper-case on case-insensitive platforms.
> Regardless how this issue ends, the documentation for {{getProcEnvironment()}} should clearly state how it deals with casing.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (EXEC-30) Make environment variables respect
casing rules of platforms
Posted by "Benjamin Bentmann (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/EXEC-30?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12617167#action_12617167 ]
Benjamin Bentmann commented on EXEC-30:
---------------------------------------
Also, maybe drop the {{synchronized}} keyword from {{EnvironmentUtil.getProcEnviroment()}}? It's only reading an effectively final variable. The method called upon {{procEnvironment}} (i.e. the code in {{DefaultProcessingEnvironment}} and derivates) is itself synchronized.
> Make environment variables respect casing rules of platforms
> ------------------------------------------------------------
>
> Key: EXEC-30
> URL: https://issues.apache.org/jira/browse/EXEC-30
> Project: Commons Exec
> Issue Type: Improvement
> Affects Versions: 1.0
> Environment: Windows
> Reporter: Benjamin Bentmann
> Priority: Critical
> Attachments: EXEC-30.patch
>
>
> Intro: Environment variables on Windows are case-insensitive (see [ExpandEnvironmentStrings|http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx]). As a little experiment, run the following code snippet on Windows with Java 1.5
> {code:java}
> System.out.println(System.getenv("PATH"));
> System.out.println(System.getenv("path"));
> System.out.println(System.getenv("Path"));
> System.out.println(System.getenv().get("PATH"));
> System.out.println(System.getenv().get("path"));
> System.out.println(System.getenv().get("Path"));
> {code}
> which can for example output
> {noformat}
> <successfully resolved variable>
> <successfully resolved variable>
> <successfully resolved variable>
> null
> null
> <successfully resolved variable>{noformat}
> IMHO, this is an example of how an API should *not* be designed. The two overloads of {{System.getenv()}} look very similar but behave completely different. Even having this documented, this subtle peculiarity makes Java programming prone to errors that prevent platform-independence.
> Commons Exec is currently providing a case-sensitive view of the Windows shell environment. This makes it effectively impossible for client to code to reliably lookup an environment variable without performing further tweaks to the map returned from {{EnvironmentUtil}}. Furthermore, these tweaks would have to be performed only depending on the current OS, so the client code would need to consider platform details. I believe this violates the basic principle of platform-independence intended by Java.
> So here my suggestion: Have Commons Exec provide a case-preserving map that obeys the casing rules of the platform for key lookup. This way, the simple code line
> {code:java}
> EnvironmentUtils.getProcEnvironment().get("PATH")
> {code}
> will consistently return the specified variable on Windows and Unix.
> Just to mention it: An alternative approach might be to have the map always be case-sensitive but normalize variable names to upper-case on case-insensitive platforms.
> Regardless how this issue ends, the documentation for {{getProcEnvironment()}} should clearly state how it deals with casing.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (EXEC-30) Make environment variables respect
casing rules of platforms
Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/EXEC-30?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12647574#action_12647574 ]
Siegfried Goeschl commented on EXEC-30:
---------------------------------------
Mhmm, didn't even know that environment variables are case-insensitive on Windows - wonder if I'm the right man for the job .... :-(
Currently I try to understand the consequences of the change - let's assume you have code under Unix that uses "$PATH" and "$Path" thereby referencing two different environment variables. In this case the code would be broken under Windows no matter what I'm doing.
I think this is an undocumented good practice to stick to uppercase environment variables and most people are simply not aware of the issue (including me) - any other opinions out there?
> Make environment variables respect casing rules of platforms
> ------------------------------------------------------------
>
> Key: EXEC-30
> URL: https://issues.apache.org/jira/browse/EXEC-30
> Project: Commons Exec
> Issue Type: Improvement
> Affects Versions: 1.0
> Environment: Windows
> Reporter: Benjamin Bentmann
> Assignee: Siegfried Goeschl
> Priority: Critical
> Attachments: EXEC-30.patch
>
>
> Intro: Environment variables on Windows are case-insensitive (see [ExpandEnvironmentStrings|http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx]). As a little experiment, run the following code snippet on Windows with Java 1.5
> {code:java}
> System.out.println(System.getenv("PATH"));
> System.out.println(System.getenv("path"));
> System.out.println(System.getenv("Path"));
> System.out.println(System.getenv().get("PATH"));
> System.out.println(System.getenv().get("path"));
> System.out.println(System.getenv().get("Path"));
> {code}
> which can for example output
> {noformat}
> <successfully resolved variable>
> <successfully resolved variable>
> <successfully resolved variable>
> null
> null
> <successfully resolved variable>{noformat}
> IMHO, this is an example of how an API should *not* be designed. The two overloads of {{System.getenv()}} look very similar but behave completely different. Even having this documented, this subtle peculiarity makes Java programming prone to errors that prevent platform-independence.
> Commons Exec is currently providing a case-sensitive view of the Windows shell environment. This makes it effectively impossible for client to code to reliably lookup an environment variable without performing further tweaks to the map returned from {{EnvironmentUtil}}. Furthermore, these tweaks would have to be performed only depending on the current OS, so the client code would need to consider platform details. I believe this violates the basic principle of platform-independence intended by Java.
> So here my suggestion: Have Commons Exec provide a case-preserving map that obeys the casing rules of the platform for key lookup. This way, the simple code line
> {code:java}
> EnvironmentUtils.getProcEnvironment().get("PATH")
> {code}
> will consistently return the specified variable on Windows and Unix.
> Just to mention it: An alternative approach might be to have the map always be case-sensitive but normalize variable names to upper-case on case-insensitive platforms.
> Regardless how this issue ends, the documentation for {{getProcEnvironment()}} should clearly state how it deals with casing.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (EXEC-30) Make environment variables respect
casing rules of platforms
Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/EXEC-30?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Siegfried Goeschl resolved EXEC-30.
-----------------------------------
Resolution: Fixed
Tested under Windows and this works.
> Make environment variables respect casing rules of platforms
> ------------------------------------------------------------
>
> Key: EXEC-30
> URL: https://issues.apache.org/jira/browse/EXEC-30
> Project: Commons Exec
> Issue Type: Improvement
> Affects Versions: 1.0
> Environment: Windows
> Reporter: Benjamin Bentmann
> Assignee: Siegfried Goeschl
> Priority: Critical
> Fix For: 1.0
>
> Attachments: EXEC-30.patch
>
>
> Intro: Environment variables on Windows are case-insensitive (see [ExpandEnvironmentStrings|http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx]). As a little experiment, run the following code snippet on Windows with Java 1.5
> {code:java}
> System.out.println(System.getenv("PATH"));
> System.out.println(System.getenv("path"));
> System.out.println(System.getenv("Path"));
> System.out.println(System.getenv().get("PATH"));
> System.out.println(System.getenv().get("path"));
> System.out.println(System.getenv().get("Path"));
> {code}
> which can for example output
> {noformat}
> <successfully resolved variable>
> <successfully resolved variable>
> <successfully resolved variable>
> null
> null
> <successfully resolved variable>{noformat}
> IMHO, this is an example of how an API should *not* be designed. The two overloads of {{System.getenv()}} look very similar but behave completely different. Even having this documented, this subtle peculiarity makes Java programming prone to errors that prevent platform-independence.
> Commons Exec is currently providing a case-sensitive view of the Windows shell environment. This makes it effectively impossible for client to code to reliably lookup an environment variable without performing further tweaks to the map returned from {{EnvironmentUtil}}. Furthermore, these tweaks would have to be performed only depending on the current OS, so the client code would need to consider platform details. I believe this violates the basic principle of platform-independence intended by Java.
> So here my suggestion: Have Commons Exec provide a case-preserving map that obeys the casing rules of the platform for key lookup. This way, the simple code line
> {code:java}
> EnvironmentUtils.getProcEnvironment().get("PATH")
> {code}
> will consistently return the specified variable on Windows and Unix.
> Just to mention it: An alternative approach might be to have the map always be case-sensitive but normalize variable names to upper-case on case-insensitive platforms.
> Regardless how this issue ends, the documentation for {{getProcEnvironment()}} should clearly state how it deals with casing.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (EXEC-30) Make environment variables respect
casing rules of platforms
Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/EXEC-30?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Siegfried Goeschl resolved EXEC-30.
-----------------------------------
Resolution: Won't Fix
Fix Version/s: 1.0
Let's see if this issue come back ...
> Make environment variables respect casing rules of platforms
> ------------------------------------------------------------
>
> Key: EXEC-30
> URL: https://issues.apache.org/jira/browse/EXEC-30
> Project: Commons Exec
> Issue Type: Improvement
> Affects Versions: 1.0
> Environment: Windows
> Reporter: Benjamin Bentmann
> Assignee: Siegfried Goeschl
> Priority: Critical
> Fix For: 1.0
>
> Attachments: EXEC-30.patch
>
>
> Intro: Environment variables on Windows are case-insensitive (see [ExpandEnvironmentStrings|http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx]). As a little experiment, run the following code snippet on Windows with Java 1.5
> {code:java}
> System.out.println(System.getenv("PATH"));
> System.out.println(System.getenv("path"));
> System.out.println(System.getenv("Path"));
> System.out.println(System.getenv().get("PATH"));
> System.out.println(System.getenv().get("path"));
> System.out.println(System.getenv().get("Path"));
> {code}
> which can for example output
> {noformat}
> <successfully resolved variable>
> <successfully resolved variable>
> <successfully resolved variable>
> null
> null
> <successfully resolved variable>{noformat}
> IMHO, this is an example of how an API should *not* be designed. The two overloads of {{System.getenv()}} look very similar but behave completely different. Even having this documented, this subtle peculiarity makes Java programming prone to errors that prevent platform-independence.
> Commons Exec is currently providing a case-sensitive view of the Windows shell environment. This makes it effectively impossible for client to code to reliably lookup an environment variable without performing further tweaks to the map returned from {{EnvironmentUtil}}. Furthermore, these tweaks would have to be performed only depending on the current OS, so the client code would need to consider platform details. I believe this violates the basic principle of platform-independence intended by Java.
> So here my suggestion: Have Commons Exec provide a case-preserving map that obeys the casing rules of the platform for key lookup. This way, the simple code line
> {code:java}
> EnvironmentUtils.getProcEnvironment().get("PATH")
> {code}
> will consistently return the specified variable on Windows and Unix.
> Just to mention it: An alternative approach might be to have the map always be case-sensitive but normalize variable names to upper-case on case-insensitive platforms.
> Regardless how this issue ends, the documentation for {{getProcEnvironment()}} should clearly state how it deals with casing.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (EXEC-30) Make environment variables respect
casing rules of platforms
Posted by "Benjamin Bentmann (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/EXEC-30?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12647581#action_12647581 ]
Benjamin Bentmann commented on EXEC-30:
---------------------------------------
Env vars are inherently platform-dependent (that's why Sun once tried to remove them from the JRE) so any Java code that (unconditionally) relies on platform-specific details such as case-sensitivity is by design not portable (in the context of Java, some people would call that broken...).
So, what are the legitimate use cases for querying the env vars? Either one sticks to variables (and their casing) that are known to work the same on all target platforms like {{PATH}} or one really queries platform-specific vars but then properly guarded by a condition to check for the current platform. That is to say, I currently don't see how good code would be negatively affected by the proposed change.
> Make environment variables respect casing rules of platforms
> ------------------------------------------------------------
>
> Key: EXEC-30
> URL: https://issues.apache.org/jira/browse/EXEC-30
> Project: Commons Exec
> Issue Type: Improvement
> Affects Versions: 1.0
> Environment: Windows
> Reporter: Benjamin Bentmann
> Assignee: Siegfried Goeschl
> Priority: Critical
> Attachments: EXEC-30.patch
>
>
> Intro: Environment variables on Windows are case-insensitive (see [ExpandEnvironmentStrings|http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx]). As a little experiment, run the following code snippet on Windows with Java 1.5
> {code:java}
> System.out.println(System.getenv("PATH"));
> System.out.println(System.getenv("path"));
> System.out.println(System.getenv("Path"));
> System.out.println(System.getenv().get("PATH"));
> System.out.println(System.getenv().get("path"));
> System.out.println(System.getenv().get("Path"));
> {code}
> which can for example output
> {noformat}
> <successfully resolved variable>
> <successfully resolved variable>
> <successfully resolved variable>
> null
> null
> <successfully resolved variable>{noformat}
> IMHO, this is an example of how an API should *not* be designed. The two overloads of {{System.getenv()}} look very similar but behave completely different. Even having this documented, this subtle peculiarity makes Java programming prone to errors that prevent platform-independence.
> Commons Exec is currently providing a case-sensitive view of the Windows shell environment. This makes it effectively impossible for client to code to reliably lookup an environment variable without performing further tweaks to the map returned from {{EnvironmentUtil}}. Furthermore, these tweaks would have to be performed only depending on the current OS, so the client code would need to consider platform details. I believe this violates the basic principle of platform-independence intended by Java.
> So here my suggestion: Have Commons Exec provide a case-preserving map that obeys the casing rules of the platform for key lookup. This way, the simple code line
> {code:java}
> EnvironmentUtils.getProcEnvironment().get("PATH")
> {code}
> will consistently return the specified variable on Windows and Unix.
> Just to mention it: An alternative approach might be to have the map always be case-sensitive but normalize variable names to upper-case on case-insensitive platforms.
> Regardless how this issue ends, the documentation for {{getProcEnvironment()}} should clearly state how it deals with casing.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (EXEC-30) Make environment variables respect casing
rules of platforms
Posted by "Benjamin Bentmann (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/EXEC-30?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Benjamin Bentmann updated EXEC-30:
----------------------------------
Attachment: EXEC-30.patch
> Make environment variables respect casing rules of platforms
> ------------------------------------------------------------
>
> Key: EXEC-30
> URL: https://issues.apache.org/jira/browse/EXEC-30
> Project: Commons Exec
> Issue Type: Improvement
> Affects Versions: 1.0
> Environment: Windows
> Reporter: Benjamin Bentmann
> Priority: Critical
> Attachments: EXEC-30.patch
>
>
> Intro: Environment variables on Windows are case-insensitive (see [ExpandEnvironmentStrings|http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx]). As a little experiment, run the following code snippet on Windows with Java 1.5
> {code:java}
> System.out.println(System.getenv("PATH"));
> System.out.println(System.getenv("path"));
> System.out.println(System.getenv("Path"));
> System.out.println(System.getenv().get("PATH"));
> System.out.println(System.getenv().get("path"));
> System.out.println(System.getenv().get("Path"));
> {code}
> which can for example output
> {noformat}
> <successfully resolved variable>
> <successfully resolved variable>
> <successfully resolved variable>
> null
> null
> <successfully resolved variable>{noformat}
> IMHO, this is an example of how an API should *not* be designed. The two overloads of {{System.getenv()}} look very similar but behave completely different. Even having this documented, this subtle peculiarity makes Java programming prone to errors that prevent platform-independence.
> Commons Exec is currently providing a case-sensitive view of the Windows shell environment. This makes it effectively impossible for client to code to reliably lookup an environment variable without performing further tweaks to the map returned from {{EnvironmentUtil}}. Furthermore, these tweaks would have to be performed only depending on the current OS, so the client code would need to consider platform details. I believe this violates the basic principle of platform-independence intended by Java.
> So here my suggestion: Have Commons Exec provide a case-preserving map that obeys the casing rules of the platform for key lookup. This way, the simple code line
> {code:java}
> EnvironmentUtils.getProcEnvironment().get("PATH")
> {code}
> will consistently return the specified variable on Windows and Unix.
> Just to mention it: An alternative approach might be to have the map always be case-sensitive but normalize variable names to upper-case on case-insensitive platforms.
> Regardless how this issue ends, the documentation for {{getProcEnvironment()}} should clearly state how it deals with casing.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (EXEC-30) Make environment variables respect
casing rules of platforms
Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/EXEC-30?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12648602#action_12648602 ]
Siegfried Goeschl commented on EXEC-30:
---------------------------------------
IMHO it is good practice to stick on a casing that works on all target platform instead of implementing workarounds for badly written program. Having said that I will update the documentation to cover this issue but not apply the patch for the time being.
The Klingon Programmer : "Our users will know fear and cower before our software! Ship it! Ship it and let them flee like the dogs they are!"
> Make environment variables respect casing rules of platforms
> ------------------------------------------------------------
>
> Key: EXEC-30
> URL: https://issues.apache.org/jira/browse/EXEC-30
> Project: Commons Exec
> Issue Type: Improvement
> Affects Versions: 1.0
> Environment: Windows
> Reporter: Benjamin Bentmann
> Assignee: Siegfried Goeschl
> Priority: Critical
> Attachments: EXEC-30.patch
>
>
> Intro: Environment variables on Windows are case-insensitive (see [ExpandEnvironmentStrings|http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx]). As a little experiment, run the following code snippet on Windows with Java 1.5
> {code:java}
> System.out.println(System.getenv("PATH"));
> System.out.println(System.getenv("path"));
> System.out.println(System.getenv("Path"));
> System.out.println(System.getenv().get("PATH"));
> System.out.println(System.getenv().get("path"));
> System.out.println(System.getenv().get("Path"));
> {code}
> which can for example output
> {noformat}
> <successfully resolved variable>
> <successfully resolved variable>
> <successfully resolved variable>
> null
> null
> <successfully resolved variable>{noformat}
> IMHO, this is an example of how an API should *not* be designed. The two overloads of {{System.getenv()}} look very similar but behave completely different. Even having this documented, this subtle peculiarity makes Java programming prone to errors that prevent platform-independence.
> Commons Exec is currently providing a case-sensitive view of the Windows shell environment. This makes it effectively impossible for client to code to reliably lookup an environment variable without performing further tweaks to the map returned from {{EnvironmentUtil}}. Furthermore, these tweaks would have to be performed only depending on the current OS, so the client code would need to consider platform details. I believe this violates the basic principle of platform-independence intended by Java.
> So here my suggestion: Have Commons Exec provide a case-preserving map that obeys the casing rules of the platform for key lookup. This way, the simple code line
> {code:java}
> EnvironmentUtils.getProcEnvironment().get("PATH")
> {code}
> will consistently return the specified variable on Windows and Unix.
> Just to mention it: An alternative approach might be to have the map always be case-sensitive but normalize variable names to upper-case on case-insensitive platforms.
> Regardless how this issue ends, the documentation for {{getProcEnvironment()}} should clearly state how it deals with casing.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (EXEC-30) Make environment variables respect
casing rules of platforms
Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/EXEC-30?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12648760#action_12648760 ]
Siegfried Goeschl commented on EXEC-30:
---------------------------------------
Okay, I double check ....
> Make environment variables respect casing rules of platforms
> ------------------------------------------------------------
>
> Key: EXEC-30
> URL: https://issues.apache.org/jira/browse/EXEC-30
> Project: Commons Exec
> Issue Type: Improvement
> Affects Versions: 1.0
> Environment: Windows
> Reporter: Benjamin Bentmann
> Assignee: Siegfried Goeschl
> Priority: Critical
> Fix For: 1.0
>
> Attachments: EXEC-30.patch
>
>
> Intro: Environment variables on Windows are case-insensitive (see [ExpandEnvironmentStrings|http://msdn.microsoft.com/en-us/library/ms724265(VS.85).aspx]). As a little experiment, run the following code snippet on Windows with Java 1.5
> {code:java}
> System.out.println(System.getenv("PATH"));
> System.out.println(System.getenv("path"));
> System.out.println(System.getenv("Path"));
> System.out.println(System.getenv().get("PATH"));
> System.out.println(System.getenv().get("path"));
> System.out.println(System.getenv().get("Path"));
> {code}
> which can for example output
> {noformat}
> <successfully resolved variable>
> <successfully resolved variable>
> <successfully resolved variable>
> null
> null
> <successfully resolved variable>{noformat}
> IMHO, this is an example of how an API should *not* be designed. The two overloads of {{System.getenv()}} look very similar but behave completely different. Even having this documented, this subtle peculiarity makes Java programming prone to errors that prevent platform-independence.
> Commons Exec is currently providing a case-sensitive view of the Windows shell environment. This makes it effectively impossible for client to code to reliably lookup an environment variable without performing further tweaks to the map returned from {{EnvironmentUtil}}. Furthermore, these tweaks would have to be performed only depending on the current OS, so the client code would need to consider platform details. I believe this violates the basic principle of platform-independence intended by Java.
> So here my suggestion: Have Commons Exec provide a case-preserving map that obeys the casing rules of the platform for key lookup. This way, the simple code line
> {code:java}
> EnvironmentUtils.getProcEnvironment().get("PATH")
> {code}
> will consistently return the specified variable on Windows and Unix.
> Just to mention it: An alternative approach might be to have the map always be case-sensitive but normalize variable names to upper-case on case-insensitive platforms.
> Regardless how this issue ends, the documentation for {{getProcEnvironment()}} should clearly state how it deals with casing.
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.