{"record":{"id":"3f124b0d32f6c185","repo":"yuliskov/SmartTube","slug":"selectionlistener-must-not-be-null-use-disablese","errorCode":null,"errorMessage":"SelectionListener must not be null. Use `disableSelectionMode()` if you want tp disable selection mode","messagePattern":"SelectionListener must not be null\\. Use `disableSelectionMode\\(\\)` if you want tp disable selection mode","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java","lineNumber":416,"sourceCode":"        if (layoutManager != null && !items.isEmpty()) {\n            layoutManager.scrollToPosition(items.size() - 1);\n        }\n    }\n\n    public void scrollToBottom() {\n        if (layoutManager != null) {\n            layoutManager.scrollToPosition(0);\n        }\n    }\n\n    /**\n     * Enables selection mode.\n     *\n     * @param selectionListener listener for selected items count. To get selected messages use {@link #getSelectedMessages()}.\n     */\n    public void enableSelectionMode(SelectionListener selectionListener) {\n        if (selectionListener == null) {\n            throw new IllegalArgumentException(\"SelectionListener must not be null. Use `disableSelectionMode()` if you want tp disable selection mode\");\n        } else {\n            this.selectionListener = selectionListener;\n        }\n    }\n\n    /**\n     * Disables selection mode and removes {@link SelectionListener}.\n     */\n    public void disableSelectionMode() {\n        this.selectionListener = null;\n        unselectAllItems();\n    }\n\n    public void enableDateHeader(boolean enable) {\n        isDateHeaderEnabled = enable;\n    }\n\n    public void enableStackFromEnd(boolean enable) {","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/yuliskov/SmartTube/blob/3de8d90593e0166f012ca18cc3c7ba45bfd68ac4/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessagesListAdapter.java#L398-L434","documentation":"enableSelectionMode stores a SelectionListener that receives selected-count callbacks during long-press multi-select. A null listener would make selection silently lose its callbacks, so the API rejects it up front with IllegalArgumentException and names disableSelectionMode() as the intentional way to switch selection off (the 'tp' typo is in the library source).","triggerScenarios":"Calling messagesListAdapter.enableSelectionMode(null) — usually a nullable listener variable in Kotlin, or an attempt to turn selection off by passing null.","commonSituations":"Trying to disable selection with enableSelectionMode(null) instead of disableSelectionMode(); conditionally wiring UI and passing a not-yet-constructed listener; refactoring listeners into optional fields.","solutions":["To switch selection off, call disableSelectionMode() — it also unselects current items","Otherwise construct and pass a non-null SelectionListener implementation","In Kotlin, make the listener non-null or pass it only after initialization"],"exampleFix":"// before\nadapter.enableSelectionMode(null); // throws\n\n// after\nadapter.disableSelectionMode();\n// or\nadapter.enableSelectionMode(count -> tv.setText(String.valueOf(count)));","handlingStrategy":"validation","validationCode":"if (listener == null) {\n    adapter.disableSelectionMode();\n} else {\n    adapter.enableSelectionMode(listener);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat disableSelectionMode() as the only way to switch selection off","Keep listener references non-null in Kotlin (no nullable var passed straight through)"],"tags":["chatkit","selection-mode","null-safety","listener"],"backgroundTag":"null-required-callback","analyzedSha":"3de8d90593e0166f012ca18cc3c7ba45bfd68ac4","analyzedAt":"2026-08-22T09:19:26.383Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}