{"record":{"id":"ba69ffd90e823ac8","repo":"chinabugotech/hutool","slug":"can-t-start-stopwatch-it-s-already-running","errorCode":null,"errorMessage":"Can't start StopWatch: it's already running","messagePattern":"Can't start StopWatch: it's already running","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/date/StopWatch.java","lineNumber":157,"sourceCode":"\n\t/**\n\t * 开始默认的新任务\n\t *\n\t * @throws IllegalStateException 前一个任务没有结束\n\t */\n\tpublic void start() throws IllegalStateException {\n\t\tstart(StrUtil.EMPTY);\n\t}\n\n\t/**\n\t * 开始指定名称的新任务\n\t *\n\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;","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/date/StopWatch.java#L139-L175","documentation":"Error \"Can't start StopWatch: it's already running\" thrown in chinabugotech/hutool.","triggerScenarios":"Thrown at hutool-core/src/main/java/cn/hutool/core/date/StopWatch.java:157 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call stop() before calling start() again on the same StopWatch.","Create a new StopWatch instance for each measurement."],"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"}