lingochamp/FileDownloader · error · IllegalArgumentException

sub package size must more than 0

Error message

sub package size must more than 0

What it means

Sentinel validation error thrown by setGlobalHandleSubPackageSize when the caller passes a sub-package size (the number of FileDownloadListener callbacks batched into one message posted to the main thread, default 5) that is zero or negative. It is a guard against an invalid global configuration: a non-positive batch size would break the message-station throttling mechanism used to avoid missing screen frames.

Solutions

  1. Pass a positive integer greater than 0 for the sub-package size, e.g. FileDownloader.getImpl().setGlobalHandleSubPackageSize(5).
  2. Validate the configured value before calling it and fall back to the default of 5 when it is not positive.
  3. If you do not need to tune the batching, simply do not call setGlobalHandleSubPackageSize and keep the library default.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at library/src/main/java/com/liulishuo/filedownloader/FileDownloader.java:176 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at library/src/main/java/com/liulishuo/filedownloader/FileDownloader.java:176

    /**
     * For avoiding missing screen frames.
     * <p/>
     * This mechanism is used for avoid methods in {@link FileDownloadListener} is invoked too
     * frequent in result the system missing screen frames in the main thread.
     * <p>
     * We wrap the message package which size is {@link FileDownloadMessageStation#SUB_PACKAGE_SIZE}
     * and post the package to the main thread with the interval:
     * {@link FileDownloadMessageStation#INTERVAL} milliseconds.
     * <p>
     * The default count of message for a message package is 5.
     *
     * @param packageSize The count of message for a message package.
     * @see #setGlobalPost2UIInterval(int)
     */
    public static void setGlobalHandleSubPackageSize(final int packageSize) {
        if (packageSize <= 0) {
            throw new IllegalArgumentException("sub package size must more than 0");
        }
        FileDownloadMessageStation.SUB_PACKAGE_SIZE = packageSize;
    }

    /**
     * Avoid missing screen frames, this leads to all callbacks in {@link FileDownloadListener} do
     * not be invoked at once when it has already achieved to ensure callbacks don't be too frequent
     *
     * @see #isEnabledAvoidDropFrame()
     * @see #setGlobalPost2UIInterval(int)
     */
    public static void enableAvoidDropFrame() {
        setGlobalPost2UIInterval(FileDownloadMessageStation.DEFAULT_INTERVAL);
    }

    /**
     * Disable avoiding missing screen frames, let all callbacks in {@link FileDownloadListener}
     * can be invoked at once when it achieve.

View on GitHub (pinned to 6237a8cac1)