{"record":{"id":"9fe0a47ec50f6eac","repo":"lingochamp/FileDownloader","slug":"if-you-start-the-task-manually-it-means-this-task","errorCode":null,"errorMessage":"If you start the task manually, it means this task doesn't belong to a queue, so you must not invoke BaseDownloadTask#ready() or InQueueTask#enqueue() before you start() this method. For detail: If this task doesn't belong to a queue, what is just an isolated task, you just need to invoke BaseDownloadTask#start() to start this task, that's all. In other words, If this task doesn't belong to a queue, you must not invoke BaseDownloadTask#ready() method or InQueueTask#enqueue() method before invoke BaseDownloadTask#start(), If you do that and if there is the same listener object to start a queue in another thread, this task may be assembled by the queue, in that case, when you invoke BaseDownloadTask#start() manually to start this task or this task is started by the queue, there is an exception buried in there, because this task object is started two times without declare BaseDownloadTask#reuse() : 1. you invoke BaseDownloadTask#start() manually; 2. the queue start this task automatically.","messagePattern":"If you start the task manually, it means this task doesn't belong to a queue, so you must not invoke BaseDownloadTask#ready\\(\\) or InQueueTask#enqueue\\(\\) before you start\\(\\) this method\\. For detail: If this task doesn't belong to a queue, what is just an isolated task, you just need to invoke BaseDownloadTask#start\\(\\) to start this task, that's all\\. In other words, If this task doesn't belong to a queue, you must not invoke BaseDownloadTask#ready\\(\\) method or InQueueTask#enqueue\\(\\) method before invoke BaseDownloadTask#start\\(\\), If you do that and if there is the same listener object to start a queue in another thread, this task may be assembled by the queue, in that case, when you invoke BaseDownloadTask#start\\(\\) manually to start this task or this task is started by the queue, there is an exception buried in there, because this task object is started two times without declare BaseDownloadTask#reuse\\(\\) : 1\\. you invoke BaseDownloadTask#start\\(\\) manually; 2\\. the queue start this task automatically\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/liulishuo/filedownloader/DownloadTask.java","lineNumber":291,"sourceCode":"    @Override\n    public boolean isRunning() {\n        //noinspection SimplifiableIfStatement\n        if (FileDownloader.getImpl().getLostConnectedHandler().isInWaitingList(this)) {\n            return true;\n        }\n\n        return FileDownloadStatus.isIng(getStatus());\n    }\n\n    @Override\n    public boolean isAttached() {\n        return mAttachKey != 0;\n    }\n\n    @Override\n    public int start() {\n        if (mIsInQueueTask) {\n            throw new IllegalStateException(\"If you start the task manually, it means this task \"\n                    + \"doesn't belong to a queue, so you must not invoke BaseDownloadTask#ready() \"\n                    + \"or InQueueTask#enqueue() before you start() this method. For detail: If this\"\n                    + \" task doesn't belong to a queue, what is just an isolated task, you just \"\n                    + \"need to invoke BaseDownloadTask#start() to start this task, that's all. In\"\n                    + \" other words, If this task doesn't belong to a queue, you must not invoke\"\n                    + \" BaseDownloadTask#ready() method or InQueueTask#enqueue() method before\"\n                    + \" invoke BaseDownloadTask#start(), If you do that and if there is the same\"\n                    + \" listener object to start a queue in another thread, this task may be \"\n                    + \"assembled by the queue, in that case, when you invoke \"\n                    + \"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    }","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/lingochamp/FileDownloader/blob/6237a8cac174bcc916e4342b14ab1ab72a5768d4/library/src/main/java/com/liulishuo/filedownloader/DownloadTask.java#L273-L309","documentation":"DownloadTask.start() throws this IllegalStateException when the task was already enqueued into a queue (mIsInQueueTask is true) but the user also calls start() manually. The library forbids manually starting a task that belongs to a FileDownloadQueueSet, because the task may otherwise be started twice (once by the queue, once manually) without a reuse() call.","triggerScenarios":"Calling FileDownloader.getImpl().start(task) (or task.start()) on a task that was added to a FileDownloadQueueSet via enqueue() and then started by queue.start().","commonSituations":"Developers mixing queue-based and standalone APIs on the same task object, e.g. adding tasks to a queue set then also calling start() directly, or holding a shared task instance started in two threads.","solutions":["Do not call start() on tasks added to a queue set; start the queue set instead (queueSet.start()).","If the task must run standalone, create it without enqueue() and call FileDownloader.getImpl().start(task).","If you genuinely need to reuse the same task object, call task.reuse() before restarting."],"exampleFix":"// before\nqueueSet.enqueue(task);\nFileDownloader.getImpl().start(task);\n\n// after\nqueueSet.enqueue(task);\nqueueSet.start();","handlingStrategy":"validation","validationCode":"if (task instanceof FileDownloadQueueSetMember || taskBelongsToQueueSet(task)) {\n    queueSet.start();\n} else {\n    FileDownloader.getImpl().start(task);\n}","typeGuard":"boolean isStandalone(BaseDownloadTask t) { return t != null && !isEnqueuedInQueueSet(t); }","tryCatchPattern":null,"preventionTips":["Never mix manual start() with queue enqueue() on the same task instance.","Start the queue set itself, not individual member tasks.","Track task ownership (queued vs standalone) in your app's state."],"tags":["android","task-lifecycle","queue","double-start"],"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"}