chinabugotech/hutool · warning · ValidateException
Index [{}] is too large for limit: [{}]
Error message
Index [{}] is too large for limit: [{}] What it means
Thrown by ListUtil.setOrPadding() when the target index exceeds the specified indexLimit. This method sets an element at a given index, padding with paddingElement if the index is beyond the current list size. The indexLimit parameter (when > 0) acts as a safety cap to prevent unbounded list growth. If index > indexLimit, a ValidateException is thrown.
Source
Thrown at hutool-core/src/main/java/cn/hutool/core/collection/ListUtil.java:451
* @param <T> 元素类型
* @param list List列表
* @param index 位置
* @param element 新元素
* @param paddingElement 填充的值
* @param indexLimit 最大索引限制
* @return 原List
* @since 5.8.28
*/
public static <T> List<T> setOrPadding(List<T> list, int index, T element, T paddingElement, int indexLimit) {
Assert.notNull(list, "List must be not null !");
final int size = list.size();
if (index < size) {
list.set(index, element);
} else {
if (indexLimit > 0) {
// issue#3286, 增加安全检查
if (index > indexLimit) {
throw new ValidateException("Index [{}] is too large for limit: [{}]", index, indexLimit);
}
}
for (int i = size; i < index; i++) {
list.add(paddingElement);
}
list.add(element);
}
return list;
}
/**
* 截取集合的部分
*
* @param <T> 集合元素类型
* @param list 被截取的数组
* @param start 开始位置(包含)
* @param end 结束位置(不包含)
* @return 截取后的数组,当开始位置超过最大时,返回空的ListView on GitHub (pinned to 8870454b2a)
Solutions
- Validate the index is within the expected range before calling setOrPadding().
- Increase the indexLimit to accommodate the expected maximum index.
- Pass indexLimit <= 0 to disable the limit check entirely (use with caution).
- Catch ValidateException and report the index as out of allowed range.
Example fix
// before
ListUtil.setOrPadding(list, 1000, value, null, 100); // throws — 1000 > 100
// after
int maxIndex = 1000;
if (index > maxIndex) throw new IllegalArgumentException("Index out of range: " + index);
ListUtil.setOrPadding(list, index, value, null, maxIndex); Defensive patterns
Strategy: validation
Validate before calling
if (indexLimit > 0 && index > indexLimit) {
throw new IllegalArgumentException("Index " + index + " exceeds limit " + indexLimit);
} Try / catch
try {
ListUtil.setOrPadding(list, index, element, padding, indexLimit);
} catch (ValidateException e) {
// index exceeds the configured limit
throw new IllegalArgumentException("Index out of allowed range", e);
} Prevention
- Validate index against the limit before calling setOrPadding().
- Set indexLimit large enough for expected indices, or pass <= 0 to disable.
- Clamp user-supplied indices to a safe maximum before use.
When it happens
Trigger: Calling ListUtil.setOrPadding(list, index, element, paddingElement, indexLimit) where index >= list.size() AND indexLimit > 0 AND index > indexLimit. For example, setOrPadding(list, 1000, x, null, 100) throws because 1000 > 100. If indexLimit is 0 or negative, the limit check is skipped entirely.
Common situations: User-supplied index values that are unreasonably large. Configuring an indexLimit that is too small for the expected indices. Off-by-one errors in index calculation. This guard was added for issue #3286 as a safety check against unbounded padding.
Related errors
- Video URI is empty
- File not found!
- Base58 checksum is invalid
- Paths or ins is empty !
- Paths length is not equals to ins length !
AI-assisted analysis of chinabugotech/hutool@8870454b2a (2026-08-14).
Data as JSON: /api/errors/3ae013a020f78c52.
Report an issue: GitHub.