diff --git a/src/org/python/core/PyStringMap.java b/src/org/python/core/PyStringMap.java index 442996c86..ea3dad3b1 100644 --- a/src/org/python/core/PyStringMap.java +++ b/src/org/python/core/PyStringMap.java @@ -637,9 +637,10 @@ public PyList keys() { @ExposedMethod(doc = BuiltinDocs.dict_keys_doc) final PyList stringmap_keys() { - PyObject[] keyArray = new PyObject[table.size()]; + Object[] keys = table.keySet().toArray(); + PyObject[] keyArray = new PyObject[keys.length]; int i = 0; - for (Object key : table.keySet()) { + for (Object key : keys) { keyArray[i++] = keyToPy(key); } return new PyList(keyArray);