lingochamp/FileDownloader · error · IllegalArgumentException

event must not be null!

Error message

event must not be null!

What it means

DownloadEventPoolImpl.publish() validates the event before dispatching; a null IDownloadEvent throws IllegalArgumentException('event must not be null!'). The pool needs event.getId() to look up listeners, so null events are rejected up front.

Solutions

  1. Ensure the event is constructed before publish; fix the producer so it never returns null
  2. Guard the publish call: if (event != null) pool.publish(event)
  3. Fix the state-machine mapping so every state yields a valid event id
  4. In test code, construct a concrete IDownloadEvent instead of passing null

Example fix

// before
pool.publish(buildEvent(state)); // buildEvent can return null
// after
IDownloadEvent event = buildEvent(state);
if (event != null) {
    pool.publish(event);
}
Defensive patterns

Strategy: type-guard

Validate before calling

// before publishing
if (event == null || event.getId() == null) {
    log.warn("Skipping publish: null event or event id");
    return;
}

Type guard

boolean isPublishable(IDownloadEvent event) {
    return event != null && event.getId() != null;
}

Try / catch

try {
    pool.publish(event);
} catch (IllegalArgumentException e) {
    log.error("publish(null) rejected by event pool; producer bug", e);
}

Prevention

When it happens

Trigger: Calling downloadEventPool.publish(null), or passing an event-producing method/factory that returned null (e.g. mapping a state to an event and the mapping has a missing case).

Common situations: State-to-event mappers with an unhandled state returning null; caching of events where the reference was cleared; tests calling publish directly with a null; custom event subclasses built conditionally and left null.

Related errors


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

Appendix: source

Thrown at library/src/main/java/com/liulishuo/filedownloader/event/DownloadEventPoolImpl.java:90

        if (container == null || listener == null) {
            return false;
        }

        synchronized (eventId.intern()) {
            boolean succeed = container.remove(listener);
            if (container.size() <= 0) {
                listenersMap.remove(eventId);
            }
            return succeed;
        }
    }

    @Override
    public boolean publish(final IDownloadEvent event) {
        if (FileDownloadLog.NEED_LOG) {
            FileDownloadLog.v(this, "publish %s", event.getId());
        }
        if (event == null) throw new IllegalArgumentException("event must not be null!");
        String eventId = event.getId();
        LinkedList<IDownloadListener> listeners = listenersMap.get(eventId);
        if (listeners == null) {
            synchronized (eventId.intern()) {
                listeners = listenersMap.get(eventId);
                if (listeners == null) {
                    if (FileDownloadLog.NEED_LOG) {
                        FileDownloadLog.d(this, "No listener for this event %s", eventId);
                    }
                    return false;
                }
            }
        }

        trigger(listeners, event);
        return true;
    }

View on GitHub (pinned to 6237a8cac1)