修复SONArray的add()方法抛出OutOfMemory异常问题

This commit is contained in:
Looly
2023-08-30 22:10:03 +08:00
parent 45e9006a94
commit 9ba8f9ca5d
3 changed files with 11 additions and 1 deletions

View File

@@ -457,6 +457,10 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
InternalJSONUtil.testValidity(element);
this.rawList.add(index, JSONUtil.wrap(element, this.config));
} else {
// issue#3286, 增加安全检查最多增加2倍
if(index > (this.size() + 1) * 2) {
throw new JSONException("Index is too large:", index);
}
while (index != this.size()) {
this.add(JSONNull.NULL);
}