{"record":{"id":"30383d3e0c5da514","repo":"lingochamp/FileDownloader","slug":"event-must-not-be-null","errorCode":null,"errorMessage":"event must not be null!","messagePattern":"event must not be null!","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/liulishuo/filedownloader/event/DownloadEventPoolImpl.java","lineNumber":90,"sourceCode":"        if (container == null || listener == null) {\n            return false;\n        }\n\n        synchronized (eventId.intern()) {\n            boolean succeed = container.remove(listener);\n            if (container.size() <= 0) {\n                listenersMap.remove(eventId);\n            }\n            return succeed;\n        }\n    }\n\n    @Override\n    public boolean publish(final IDownloadEvent event) {\n        if (FileDownloadLog.NEED_LOG) {\n            FileDownloadLog.v(this, \"publish %s\", event.getId());\n        }\n        if (event == null) throw new IllegalArgumentException(\"event must not be null!\");\n        String eventId = event.getId();\n        LinkedList<IDownloadListener> listeners = listenersMap.get(eventId);\n        if (listeners == null) {\n            synchronized (eventId.intern()) {\n                listeners = listenersMap.get(eventId);\n                if (listeners == null) {\n                    if (FileDownloadLog.NEED_LOG) {\n                        FileDownloadLog.d(this, \"No listener for this event %s\", eventId);\n                    }\n                    return false;\n                }\n            }\n        }\n\n        trigger(listeners, event);\n        return true;\n    }\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/lingochamp/FileDownloader/blob/6237a8cac174bcc916e4342b14ab1ab72a5768d4/library/src/main/java/com/liulishuo/filedownloader/event/DownloadEventPoolImpl.java#L72-L108","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\npool.publish(buildEvent(state)); // buildEvent can return null\n// after\nIDownloadEvent event = buildEvent(state);\nif (event != null) {\n    pool.publish(event);\n}","handlingStrategy":"type-guard","validationCode":"// before publishing\nif (event == null || event.getId() == null) {\n    log.warn(\"Skipping publish: null event or event id\");\n    return;\n}","typeGuard":"boolean isPublishable(IDownloadEvent event) {\n    return event != null && event.getId() != null;\n}","tryCatchPattern":"try {\n    pool.publish(event);\n} catch (IllegalArgumentException e) {\n    log.error(\"publish(null) rejected by event pool; producer bug\", e);\n}","preventionTips":["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"],"tags":["android","filedownloader","null-argument","event-publish"],"backgroundTag":"null-argument","analyzedSha":"6237a8cac174bcc916e4342b14ab1ab72a5768d4","analyzedAt":"2026-09-08T23:50:48.168Z","contentChangedAt":"2026-09-08T23:50:48.168Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}