chinabugotech/hutool · error · IllegalStateException

No tasks run: can't get last task interval

Error message

No tasks run: can't get last task interval

What it means

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

Source

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

	/**
	 * 获取当前任务名,{@code null} 表示无任务
	 *
	 * @return 当前任务名,{@code null} 表示无任务
	 * @see #isRunning()
	 */
	public String currentTaskName() {
		return this.currentTaskName;
	}

	/**
	 * 获取最后任务的花费时间(纳秒)
	 *
	 * @return 任务的花费时间(纳秒)
	 * @throws IllegalStateException 无任务
	 */
	public long getLastTaskTimeNanos() throws IllegalStateException {
		if (this.lastTaskInfo == null) {
			throw new IllegalStateException("No tasks run: can't get last task interval");
		}
		return this.lastTaskInfo.getTimeNanos();
	}

	/**
	 * 获取最后任务的花费时间(毫秒)
	 *
	 * @return 任务的花费时间(毫秒)
	 * @throws IllegalStateException 无任务
	 */
	public long getLastTaskTimeMillis() throws IllegalStateException {
		if (this.lastTaskInfo == null) {
			throw new IllegalStateException("No tasks run: can't get last task interval");
		}
		return this.lastTaskInfo.getTimeMillis();
	}

	/**

View on GitHub (pinned to 8870454b2a)

Solutions

  1. Run at least one start()/stop() cycle before querying the last task interval.
  2. Check getTaskCount() > 0 before accessing last task info.

When it happens

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