diff --git a/JSONObject.java b/JSONObject.java index 399f093c1..d442aff31 100755 --- a/JSONObject.java +++ b/JSONObject.java @@ -1128,14 +1128,16 @@ public JSONObject put(String key, Object value) throws JSONException { } if (value != null) { testValidity(value); - pooled = (String)keyPool.get(key); - if (pooled == null) { - if (keyPool.size() >= keyPoolSize) { + synchronized (JSONObject.class) { + pooled = (String)keyPool.get(key); + if (pooled == null) { + if (keyPool.size() >= keyPoolSize) { keyPool = new HashMap(keyPoolSize); - } - keyPool.put(key, key); - } else { - key = pooled; + } + keyPool.put(key, key); + } else { + key = pooled; + } } this.map.put(key, value); } else {