{"record":{"id":"ee60d095ae0c48ee","repo":"chinabugotech/hutool","slug":"can-t-stop-stopwatch-it-s-not-running","errorCode":null,"errorMessage":"Can't stop StopWatch: it's not running","messagePattern":"Can't stop StopWatch: it's not running","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/date/StopWatch.java","lineNumber":170,"sourceCode":"\t * @param taskName 新开始的任务名称\n\t * @throws IllegalStateException 前一个任务没有结束\n\t */\n\tpublic void start(String taskName) throws IllegalStateException {\n\t\tif (null != this.currentTaskName) {\n\t\t\tthrow new IllegalStateException(\"Can't start StopWatch: it's already running\");\n\t\t}\n\t\tthis.currentTaskName = taskName;\n\t\tthis.startTimeNanos = System.nanoTime();\n\t}\n\n\t/**\n\t * 停止当前任务\n\t *\n\t * @throws IllegalStateException 任务没有开始\n\t */\n\tpublic void stop() throws IllegalStateException {\n\t\tif (null == this.currentTaskName) {\n\t\t\tthrow new IllegalStateException(\"Can't stop StopWatch: it's not running\");\n\t\t}\n\n\t\tfinal long lastTime = System.nanoTime() - this.startTimeNanos;\n\t\tfinal long safeLastTime = Math.max(0, lastTime);\n\t\tthis.totalTimeNanos += safeLastTime;\n\t\tthis.lastTaskInfo = new TaskInfo(this.currentTaskName, safeLastTime);\n\t\tif (null != this.taskList) {\n\t\t\tthis.taskList.add(this.lastTaskInfo);\n\t\t}\n\t\t++this.taskCount;\n\t\tthis.currentTaskName = null;\n\t}\n\n\t/**\n\t * 检查是否有正在运行的任务\n\t *\n\t * @return 是否有正在运行的任务\n\t * @see #currentTaskName()","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/date/StopWatch.java#L152-L188","documentation":"Error \"Can't stop StopWatch: it's not running\" thrown in chinabugotech/hutool.","triggerScenarios":"Thrown at hutool-core/src/main/java/cn/hutool/core/date/StopWatch.java:170 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call start() before stop(); ensure the StopWatch is running.","Guard with isRunning() before calling stop()."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}