Skip to content

Commit 6c83bd2

Browse files
committed
minor: added assert when initialising HashMapStorage from LinkedHashMap
1 parent 13f4fb3 commit 6c83bd2

File tree

1 file changed

+11
-1
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common

1 file changed

+11
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashMapStorage.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -88,9 +88,19 @@ public HashMapStorage() {
8888
}
8989

9090
public HashMapStorage(LinkedHashMap<Object, Object> map) {
91+
assert hasStringKeys(map) : "keys in HashMapStorage have to be java.lang.String";
9192
values = map;
9293
}
9394

95+
private static boolean hasStringKeys(LinkedHashMap<Object, Object> map) {
96+
for (Object k : map.keySet()) {
97+
if (!(k instanceof String)) {
98+
return false;
99+
}
100+
}
101+
return true;
102+
}
103+
94104
@TruffleBoundary
95105
private static LinkedHashMap<Object, Object> newHashMap() {
96106
return new LinkedHashMap<>();

0 commit comments

Comments
 (0)