lingochamp/FileDownloader · error · IllegalStateException

This task is running

Error message

This task is running %d, if you want to start the same task, please create a new one by FileDownloader.create

What it means

startTaskUnchecked() throws this IllegalStateException when starting a task that is currently running (isUsing() && isRunning()). FileDownloader task objects are single-use while running; to repeat the download you must create a fresh task via FileDownloader.create.

Solutions

  1. Create a new task with FileDownloader.getImpl().create(url, path) before starting again.
  2. Check the task status before starting (FileDownloader.getImpl().getStatus(...)) and skip if already running.
  3. If the previous run finished, call task.reuse() then restart.

Example fix

// before
if (!task.isRunning()) return;
task.start();

// after
if (FileDownloader.getImpl().getStatus(url, path)) return;
DownloadTask task = FileDownloader.getImpl().create(url, path);
task.start();
Defensive patterns

Strategy: validation

Validate before calling

if (FileDownloader.getImpl().getStatus(url, path)) return; // already running
DownloadTask task = FileDownloader.getImpl().create(url, path);
task.start();

Type guard

boolean safeToStart(BaseDownloadTask t) { return !t.isRunning(); }

Prevention

When it happens

Trigger: Calling start() (manually, from a queue, or from rescue) on a DownloadTask that is already in the running state.

Common situations: Reusing a captured task variable to retry a download while the first attempt is still active; click handlers that start the same task object repeatedly.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of lingochamp/FileDownloader@6237a8cac1 (2026-09-08). Data as JSON: /api/errors/9b68ef777abbc89e. Report an issue: GitHub.

Appendix: source

Thrown at library/src/main/java/com/liulishuo/filedownloader/DownloadTask.java:314

                    + " 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.");
        }

        return startTaskUnchecked();
    }

    private int startTaskUnchecked() {
        if (isUsing()) {
            if (isRunning()) {
                throw new IllegalStateException(
                        FileDownloadUtils.formatString("This task is running %d, if you"
                                + " want to start the same task, please create a new one by"
                                + " FileDownloader.create", getId()));
            } else {
                throw new IllegalStateException("This task is dirty to restart, If you want to "
                        + "reuse this task, please invoke #reuse method manually and retry to "
                        + "restart again." + mHunter.toString());
            }
        }

        if (!isAttached()) {
            setAttachKeyDefault();
        }

        mHunter.intoLaunchPool();

        return getId();
    }

View on GitHub (pinned to 6237a8cac1)