{"record":{"id":"3760f31316d78ccd","repo":"yuliskov/SmartTube","slug":"contentchecker-cannot-be-null-when-using-custom-co","errorCode":null,"errorMessage":"ContentChecker cannot be null when using custom content types!","messagePattern":"ContentChecker cannot be null when using custom content types!","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java","lineNumber":665,"sourceCode":"        } catch (Exception e) {\n            throw new UnsupportedOperationException(\"Somehow we couldn't create the ViewHolder for message. Please, report this issue on GitHub with full stacktrace in description.\", e);\n        }\n    }\n\n    @SuppressWarnings(\"unchecked\")\n    private short getContentViewType(IMessage message) {\n        if (message instanceof MessageContentType.Image\n                && ((MessageContentType.Image) message).getImageUrl() != null) {\n            return VIEW_TYPE_IMAGE_MESSAGE;\n        }\n\n        // other default types will be here\n\n        if (message instanceof MessageContentType) {\n            for (int i = 0; i < customContentTypes.size(); i++) {\n                ContentTypeConfig config = customContentTypes.get(i);\n                if (contentChecker == null) {\n                    throw new IllegalArgumentException(\"ContentChecker cannot be null when using custom content types!\");\n                }\n                boolean hasContent = contentChecker.hasContentFor(message, config.type);\n                if (hasContent) return config.type;\n            }\n        }\n\n        return VIEW_TYPE_TEXT_MESSAGE;\n    }\n\n    /*\n     * HOLDERS\n     * */\n\n    /**\n     * The base class for view holders for incoming and outcoming message.\n     * You can extend it to create your own holder in conjuction with custom layout or even using default layout.\n     */\n    public static abstract class BaseMessageViewHolder<MESSAGE extends IMessage> extends ViewHolder<MESSAGE> {","sourceCodeStart":647,"sourceCodeEnd":683,"githubUrl":"https://github.com/yuliskov/SmartTube/blob/3de8d90593e0166f012ca18cc3c7ba45bfd68ac4/chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java#L647-L683","documentation":"When a message implements MessageContentType and at least one custom content type is registered, getContentViewType must ask the ContentChecker which type the message carries; if the checker field is null at that moment it throws IllegalArgumentException. registerContentType assigns the checker, but its @NonNull is annotation-only, so a null passed at registration compiles fine and detonates later at layout time when the first such message is measured.","triggerScenarios":"Calling any registerContentType(...) overload with a null ContentChecker and later adding a message whose class implements MessageContentType; reaching getContentViewType's loop with customContentTypes non-empty and contentChecker never assigned.","commonSituations":"Kotlin callers passing a nullable checker through a platform type without a compile error; trimming sample code and dropping the checker argument; adding MessageContentType to the message model while intending to keep only built-in text/image rendering.","solutions":["Pass a real ContentChecker to every registerContentType call, e.g. (message, type) -> message instanceof MyContentMsg","If messages only need text/image rendering, do not implement MessageContentType on the model class","Assert non-null at registration (Objects.requireNonNull) so failure happens next to the buggy call, not during layout"],"exampleFix":"// before\nholders.registerContentType((byte) 1, InVH.class, R.layout.in, OutVH.class, R.layout.out, null);\n\n// after\nholders.registerContentType((byte) 1, InVH.class, R.layout.in, OutVH.class, R.layout.out,\n        (message, type) -> message instanceof MyContentMsg);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(checker, \"ContentChecker is required when registering content types\");\nholders.registerContentType(type, inHolder, inLayout, outHolder, outLayout, checker);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass null as the ContentChecker — @NonNull here is annotation-only","Only implement MessageContentType on models that actually carry custom content","Fail fast with requireNonNull at registration so the stacktrace points at the real bug"],"tags":["chatkit","content-checker","null-safety","callbacks","messages"],"backgroundTag":"null-required-callback","analyzedSha":"3de8d90593e0166f012ca18cc3c7ba45bfd68ac4","analyzedAt":"2026-08-22T09:19:26.383Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}