mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user