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