mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
a3efec9c52
commit
b0eea9f919
@ -337,7 +337,8 @@ public class BeanUtil {
|
||||
if (bean instanceof Map) {
|
||||
((Map) bean).put(fieldNameOrIndex, value);
|
||||
} else if (bean instanceof List) {
|
||||
ListUtil.setOrPadding((List) bean, Convert.toInt(fieldNameOrIndex), value);
|
||||
// 相对于5.x逻辑变更,与数组逻辑保持一致
|
||||
ListUtil.setOrAppend((List) bean, Convert.toInt(fieldNameOrIndex), value);
|
||||
} else if (ArrayUtil.isArray(bean)) {
|
||||
// issue#3008,追加产生新数组,此处返回新数组
|
||||
return ArrayUtil.setOrAppend(bean, Convert.toInt(fieldNameOrIndex), value);
|
||||
|
@ -20,6 +20,7 @@ import org.dromara.hutool.core.collection.partition.RandomAccessAvgPartition;
|
||||
import org.dromara.hutool.core.collection.partition.RandomAccessPartition;
|
||||
import org.dromara.hutool.core.comparator.PinyinComparator;
|
||||
import org.dromara.hutool.core.comparator.PropertyComparator;
|
||||
import org.dromara.hutool.core.exception.HutoolException;
|
||||
import org.dromara.hutool.core.lang.Assert;
|
||||
import org.dromara.hutool.core.lang.page.PageInfo;
|
||||
import org.dromara.hutool.core.util.ObjUtil;
|
||||
@ -464,7 +465,7 @@ public class ListUtil {
|
||||
*
|
||||
* @param <T> 元素类型
|
||||
* @param list List列表
|
||||
* @param index 位置
|
||||
* @param index 位置,不能大于(list.size()+1) * 2
|
||||
* @param element 新元素
|
||||
* @param paddingElement 填充的值
|
||||
* @return 原List
|
||||
@ -476,6 +477,10 @@ public class ListUtil {
|
||||
if (index < size) {
|
||||
list.set(index, element);
|
||||
} else {
|
||||
// issue#3286, 增加安全检查,最多增加2倍
|
||||
if(index > (list.size() + 1) * 2) {
|
||||
throw new HutoolException("Index is too large:", index);
|
||||
}
|
||||
for (int i = size; i < index; i++) {
|
||||
list.add(paddingElement);
|
||||
}
|
||||
|
@ -456,13 +456,7 @@ public class JSONArray implements JSON, JSONGetter<Integer>, List<Object>, Rando
|
||||
}
|
||||
this.rawList.add(index, InternalJSONUtil.wrap(element, this.config));
|
||||
} else {
|
||||
// issue#3286, 如果用户指定的index太大,容易造成Java heap space错误。
|
||||
// if (!config.isIgnoreNullValue()) {
|
||||
// while (index != this.size()) {
|
||||
// // 非末尾,则填充null
|
||||
// this.add(null);
|
||||
// }
|
||||
// }
|
||||
// 相对于5.x逻辑变更,当index大于size,则追加,而不是补充null,这样更加安全
|
||||
this.add(element);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user