{"record":{"id":"b83098dbccc3626a","repo":"lingochamp/FileDownloader","slug":"this-task-is-dirty-to-restart-if-you-want-to-reus","errorCode":null,"errorMessage":"This task is dirty to restart, If you want to reuse this task, please invoke #reuse method manually and retry to restart again.","messagePattern":"This task is dirty to restart, If you want to reuse this task, please invoke #reuse method manually and retry to restart again\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/liulishuo/filedownloader/DownloadTask.java","lineNumber":319,"sourceCode":"                    + \"BaseDownloadTask#start() manually to start this task or this task is started\"\n                    + \" by the queue, there is an exception buried in there, because this task\"\n                    + \" object is started two times without declare BaseDownloadTask#reuse() :\"\n                    + \" 1. you invoke BaseDownloadTask#start() manually; \"\n                    + \" 2. the queue start this task automatically.\");\n        }\n\n        return startTaskUnchecked();\n    }\n\n    private int startTaskUnchecked() {\n        if (isUsing()) {\n            if (isRunning()) {\n                throw new IllegalStateException(\n                        FileDownloadUtils.formatString(\"This task is running %d, if you\"\n                                + \" want to start the same task, please create a new one by\"\n                                + \" FileDownloader.create\", getId()));\n            } else {\n                throw new IllegalStateException(\"This task is dirty to restart, If you want to \"\n                        + \"reuse this task, please invoke #reuse method manually and retry to \"\n                        + \"restart again.\" + mHunter.toString());\n            }\n        }\n\n        if (!isAttached()) {\n            setAttachKeyDefault();\n        }\n\n        mHunter.intoLaunchPool();\n\n        return getId();\n    }\n\n    // -------------- Another Operations ---------------------\n\n    private final Object mPauseLock;\n","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/lingochamp/FileDownloader/blob/6237a8cac174bcc916e4342b14ab1ab72a5768d4/library/src/main/java/com/liulishuo/filedownloader/DownloadTask.java#L301-L337","documentation":"startTaskUnchecked() throws this IllegalStateException when the task is used (isUsing()) but not running and its hunter state indicates it is dirty — i.e. it has completed a lifecycle and cannot simply be restarted without reset. The library requires an explicit reuse() call to reset internal state before starting again.","triggerScenarios":"Calling start() on a task object that was already started once and finished (paused, completed, or warned), without invoking BaseDownloadTask#reuse() first.","commonSituations":"Retrying a finished download with the same task instance; re-running a task after pause() without reuse().","solutions":["Call task.reuse() before invoking start() again.","Create a new task via FileDownloader.getImpl().create(url, path) instead of restarting the old one."],"exampleFix":"// before\ntask.start(); // second time\n\n// after\ntask.reuse();\ntask.start();","handlingStrategy":"validation","validationCode":"if (task.isRunning()) return;\ntask.reuse();\ntask.start();","typeGuard":null,"tryCatchPattern":"try { task.start(); } catch (IllegalStateException e) { task.reuse(); task.start(); }","preventionTips":["Call reuse() before any second start on the same instance.","Prefer new task creation over restarting old instances.","Centralize start logic in one helper that handles reuse."],"tags":["android","task-lifecycle","reuse"],"backgroundTag":"invalid-state-transition","analyzedSha":"6237a8cac174bcc916e4342b14ab1ab72a5768d4","analyzedAt":"2026-09-08T23:50:48.168Z","contentChangedAt":"2026-09-08T23:50:48.168Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}