lingochamp/FileDownloader · error · NullPointerException

name == null

Error message

name == null

What it means

A precondition check inside FileDownloadHeader.add: a request header cannot be registered without a name, so passing a null header name is rejected (typically IllegalArgumentException). The faulty input is the 'name' argument of add(name, value).

Solutions

  1. Pass a non-null header name, e.g. header.add("User-Agent", value)
  2. Null-check the header name before calling add when it comes from dynamic/user input
  3. Build headers only from known constants rather than external unvalidated strings
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at library/src/main/java/com/liulishuo/filedownloader/model/FileDownloadHeader.java:41 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/043d74a28dfa09f7. Report an issue: GitHub.

Appendix: source

Thrown at library/src/main/java/com/liulishuo/filedownloader/model/FileDownloadHeader.java:41

import java.util.HashMap;
import java.util.List;

/**
 * We have already handled Etag internal for guaranteeing tasks resuming from the breakpoint, in
 * other words, if the task has downloaded and got Etag, we will add the 'If-Match' and the 'Range'
 * K-V to its request header automatically.
 */
public class FileDownloadHeader implements Parcelable {

    private HashMap<String, List<String>> mHeaderMap;

    /**
     * We have already handled etag, and will add 'If-Match' & 'Range' value if it works.
     *
     * @see com.liulishuo.filedownloader.download.ConnectTask#addUserRequiredHeader
     */
    public void add(String name, String value) {
        if (name == null) throw new NullPointerException("name == null");
        if (name.isEmpty()) throw new IllegalArgumentException("name is empty");
        if (value == null) throw new NullPointerException("value == null");

        if (mHeaderMap == null) {
            mHeaderMap = new HashMap<>();
        }

        List<String> values = mHeaderMap.get(name);
        if (values == null) {
            values = new ArrayList<>();
            mHeaderMap.put(name, values);
        }

        if (!values.contains(value)) {
            values.add(value);
        }
    }

View on GitHub (pinned to 6237a8cac1)