yuliskov/SmartTube · error · IllegalArgumentException

content type must be greater or less than '0'!

Error message

content type must be greater or less than '0'!

What it means

MessageHolders encodes message direction in the sign of the view type (positive incoming, negative outcoming), so byte 0 cannot represent a usable content type and registerContentType rejects it up front with IllegalArgumentException. Built-in view types occupy 130-133 (date header, text, image, string header); registration happens once, before the adapter is used.

Source

Thrown at chatkit/src/main/java/com/stfalcon/chatkit/messages/MessageHolders.java:483

     * Registers custom content type (e.g. multimedia, events etc.)
     *
     * @param type            unique id for content type
     * @param incomingHolder  holder class for incoming message
     * @param outcomingHolder holder class for outcoming message
     * @param incomingLayout  layout resource for incoming message
     * @param outcomingLayout layout resource for outcoming message
     * @param contentChecker  {@link ContentChecker} for registered type
     * @return {@link MessageHolders} for subsequent configuration.
     */
    public <TYPE extends MessageContentType>
    MessageHolders registerContentType(
            byte type,
            @NonNull Class<? extends BaseMessageViewHolder<TYPE>> incomingHolder, @LayoutRes int incomingLayout,
            @NonNull Class<? extends BaseMessageViewHolder<TYPE>> outcomingHolder, @LayoutRes int outcomingLayout,
            @NonNull ContentChecker contentChecker) {

        if (type == 0)
            throw new IllegalArgumentException("content type must be greater or less than '0'!");

        customContentTypes.add(
                new ContentTypeConfig<>(type,
                        new HolderConfig<>(incomingHolder, incomingLayout),
                        new HolderConfig<>(outcomingHolder, outcomingLayout)));
        this.contentChecker = contentChecker;
        return this;
    }

    /**
     * Registers custom content type (e.g. multimedia, events etc.)
     *
     * @param type             unique id for content type
     * @param incomingHolder   holder class for incoming message
     * @param outcomingHolder  holder class for outcoming message
     * @param incomingPayload  payload for incoming message
     * @param outcomingPayload payload for outcoming message
     * @param incomingLayout   layout resource for incoming message

View on GitHub (pinned to 3de8d90593)

Solutions

  1. Use a non-zero byte for the content type, e.g. (byte) 1
  2. Start generated/looped type numbering at 1 and keep values unique across registrations
  3. Keep custom types out of the built-in range 130-133 so getViewHolder routes them to your holders instead of the defaults

Example fix

// before
holders.registerContentType((byte) 0, InVH.class, R.layout.in, OutVH.class, R.layout.out, checker);

// after
holders.registerContentType((byte) 1, InVH.class, R.layout.in, OutVH.class, R.layout.out, checker);
Defensive patterns

Strategy: validation

Validate before calling

if (type == 0) throw new IllegalArgumentException("content type must be non-zero");
holders.registerContentType(type, inHolder, inLayout, outHolder, outLayout, checker);

Prevention

When it happens

Trigger: Calling registerContentType((byte) 0, incomingHolder, ..., contentChecker) with a default-initialized type constant, or a loop that starts numbering custom types at 0.

Common situations: Porting an enum of content types whose ordinal starts at zero; copy-pasting a registration block and forgetting to change the type byte; auto-generated type tables beginning at 0.

Related errors


AI-assisted analysis of yuliskov/SmartTube@3de8d90593 (2026-08-22). Data as JSON: /api/errors/9f4511f9a4602a05. Report an issue: GitHub.