From 58ddc179d494fd426aca184a1a5749d9fa6f81b9 Mon Sep 17 00:00:00 2001 From: Matthias Klose Date: Wed, 22 Oct 2008 18:19:29 +0000 Subject: Import GNU Classpath (libgcj-import-20081021). 2008-10-22 Matthias Klose Import GNU Classpath (libgcj-import-20081021). * Regenerate class and header files. * Regenerate auto* files. From-SVN: r141302 --- libjava/classpath/java/lang/System.java | 28 ++++++++++++++++++---------- libjava/classpath/java/lang/ThreadLocal.java | 7 ++++--- 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'libjava/classpath/java/lang') diff --git a/libjava/classpath/java/lang/System.java b/libjava/classpath/java/lang/System.java index 9fd6bfe..58b1bba 100644 --- a/libjava/classpath/java/lang/System.java +++ b/libjava/classpath/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 environ = (List)VMSystem.environ(); Map 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); + List environ = (List)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); + variables.put(key, value); + } + } + + environmentMap = Collections.unmodifiableMap(variables); } + return environmentMap; } diff --git a/libjava/classpath/java/lang/ThreadLocal.java b/libjava/classpath/java/lang/ThreadLocal.java index 14778c6..1f60a55 100644 --- a/libjava/classpath/java/lang/ThreadLocal.java +++ b/libjava/classpath/java/lang/ThreadLocal.java @@ -90,7 +90,7 @@ public class ThreadLocal * user. Do not expose this to the public. Package visible for use by * InheritableThreadLocal */ - static final Object notFound = new Object(); + static final Object sentinel = new Object(); /** * The base for the computation of the next hash for a thread local. @@ -100,7 +100,8 @@ public class ThreadLocal /** * Allocate a new hash. */ - private synchronized int computeNextHash() { + private synchronized int computeNextHash() + { return nextHashBase++ * 6709; } @@ -144,7 +145,7 @@ public class ThreadLocal // Note that we don't have to synchronize, as only this thread will // ever modify the map. T value = (T) map.get(this); - if (value == notFound) + if (value == sentinel) { value = initialValue(); map.set(this, value); -- cgit v1.1