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
- Ensure the event is constructed before publish; fix the producer so it never returns null
- Guard the publish call: if (event != null) pool.publish(event)
- Fix the state-machine mapping so every state yields a valid event id
- 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
- Make event-producing methods return Optional<IDownloadEvent> or non-null always, so callers cannot publish null
- Ensure state-to-event mappings cover every state; add a default branch that throws early at the producer
- Null-check results of cached/conditional event construction before publish
- Unit-test your event factory across all states to guarantee non-null output
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
- listener must not be null!
- can't generate real path, the file name is null
- can't generate real path, the directory is null
- connection is null when findEtag
- create FileDownloadQueueSet must with valid target!
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)