chinabugotech/hutool · error · IllegalStateException

No tasks run: can't get last task info

Error message

No tasks run: can't get last task info

What it means

Error "No tasks run: can't get last task info" thrown in chinabugotech/hutool.

Source

Thrown at hutool-core/src/main/java/cn/hutool/core/date/StopWatch.java:251

	 * @return 任务名
	 * @throws IllegalStateException 无任务
	 */
	public String getLastTaskName() throws IllegalStateException {
		if (this.lastTaskInfo == null) {
			throw new IllegalStateException("No tasks run: can't get last task name");
		}
		return this.lastTaskInfo.getTaskName();
	}

	/**
	 * 获取最后的任务对象
	 *
	 * @return {@link TaskInfo} 任务对象,包括任务名和花费时间
	 * @throws IllegalStateException 无任务
	 */
	public TaskInfo getLastTaskInfo() throws IllegalStateException {
		if (this.lastTaskInfo == null) {
			throw new IllegalStateException("No tasks run: can't get last task info");
		}
		return this.lastTaskInfo;
	}

	/**
	 * 获取所有任务的总花费时间
	 *
	 * @param unit 时间单位,{@code null}表示默认{@link TimeUnit#NANOSECONDS}
	 * @return 花费时间
	 * @since 5.7.16
	 */
	public long getTotal(TimeUnit unit){
		return unit.convert(this.totalTimeNanos, TimeUnit.NANOSECONDS);
	}

	/**
	 * 获取所有任务的总花费时间(纳秒)
	 *

View on GitHub (pinned to 8870454b2a)

Solutions

  1. Run at least one task before requesting the last task info.
  2. Check getTaskCount() > 0 before calling getLastTaskInfo().

When it happens

Trigger: Thrown at hutool-core/src/main/java/cn/hutool/core/date/StopWatch.java:251 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/cc361397a1ab8bcb. Report an issue: GitHub.