chinabugotech/hutool · error · IllegalArgumentException
Seconds must be a positive number!
Error message
Seconds must be a positive number!
What it means
Error "Seconds must be a positive number!" thrown in chinabugotech/hutool.
Source
Thrown at hutool-core/src/main/java/cn/hutool/core/date/DateUtil.java:1969
int result = 0;
for (int i = lastIndex; i >= 0; i--) {
result += Integer.parseInt(hms.get(i)) * Math.pow(60, (lastIndex - i));
}
return result;
}
/**
* 秒数转为时间格式(HH:mm:ss)<br>
* 参考:<a href="https://github.com/iceroot">https://github.com/iceroot</a>
*
* @param seconds 需要转换的秒数
* @return 转换后的字符串
* @since 3.1.2
*/
public static String secondToTime(int seconds) {
if (seconds < 0) {
throw new IllegalArgumentException("Seconds must be a positive number!");
}
int hour = seconds / 3600;
int other = seconds % 3600;
int minute = other / 60;
int second = other % 60;
final StringBuilder sb = new StringBuilder();
if (hour < 10) {
sb.append("0");
}
sb.append(hour);
sb.append(":");
if (minute < 10) {
sb.append("0");
}
sb.append(minute);
sb.append(":");
if (second < 10) {View on GitHub (pinned to 8870454b2a)
Solutions
- Pass a positive number of seconds; validate the argument before the call.
- Use Math.max(1, seconds) if a non-positive value may flow in.
When it happens
Trigger: Thrown at hutool-core/src/main/java/cn/hutool/core/date/DateUtil.java:1969 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of chinabugotech/hutool@8870454b2a (2026-08-14).
Data as JSON: /api/errors/ca11b56674dfb45a.
Report an issue: GitHub.