summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMario Torre <neugens@limasoftware.net>2008-09-16 19:41:44 +0000
committerMario Torre <neugens@limasoftware.net>2008-09-16 19:41:44 +0000
commit98a6bf8245b026ac975b529568ebd3e06e656ed4 (patch)
tree758c3503a5ae0871250a0b85524233ded738da57
parentf3b882e136b4b0da2d86ef2f714d713a02baa40e (diff)
downloadclasspath-98a6bf8245b026ac975b529568ebd3e06e656ed4.tar.gz
2008-09-16 Mario Torre <neugens@aicas.com>
* java/lang/System.java (getenv): Fix env entries of the form key=value=value=value not parsed correctly.
-rw-r--r--ChangeLog5
-rw-r--r--java/lang/System.java30
2 files changed, 24 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index dbc3b5d09..e381c0faa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-09-16 Mario Torre <neugens@aicas.com>
+
+ * java/lang/System.java (getenv): Fix env entries of the form
+ key=value=value=value not parsed correctly.
+
2008-09-15 Andrew John Hughes <gnu_andrew@member.fsf.org>
Reported by: Matthias Klose
diff --git a/java/lang/System.java b/java/lang/System.java
index 9fd6bfe12..6be313155 100644
--- a/java/lang/System.java
+++ b/java/lang/System.java
@@ -546,20 +546,28 @@ public final class System
SecurityManager sm = SecurityManager.current; // Be thread-safe.
if (sm != null)
sm.checkPermission(new RuntimePermission("getenv.*"));
+
if (environmentMap == null)
{
- List<String> environ = (List<String>)VMSystem.environ();
- Map<String,String> variables = new EnvironmentMap();
- for (String pair : environ)
- {
- String[] parts = pair.split("=");
- if (parts.length == 2)
- variables.put(parts[0], parts[1]);
- else
- variables.put(parts[0], "");
- }
- environmentMap = Collections.unmodifiableMap(variables);
+ Map<String, String> _map = new HashMap();
+ List<String> environ = (List<String>)VMSystem.environ();
+ for (String envEntry : environ)
+ {
+ // avoid broken and null entries
+ if (envEntry != null && !envEntry.endsWith("="))
+ {
+ // it's perfectly legal that some entries may be in the form
+ // key=value=value=value
+ int equalSignIndex = envEntry.indexOf('=');
+ String key = envEntry.substring(0, equalSignIndex);
+ String value = envEntry.substring(equalSignIndex + 1);
+ _map.put(key, value);
+ }
+ }
+
+ environmentMap = Collections.unmodifiableMap(_map);
}
+
return environmentMap;
}