yuliskov/SmartTube · error · IllegalStateException

Can't find matched preference for type: ${category.type}

Error message

Can't find matched preference for type: ${category.type}

What it means

AppPreferenceManager.createPreference(category) dispatches on category.type through a switch covering TYPE_CHECKBOX_LIST, TYPE_RADIO_LIST, TYPE_STRING_LIST, TYPE_SINGLE_SWITCH, TYPE_SINGLE_BUTTON, TYPE_LONG_TEXT, TYPE_CHAT and TYPE_COMMENTS. An OptionCategory whose type matches none of these falls out of the switch and throws IllegalStateException('Can't find matched preference for type: ' + category.type) — the app received an option category it cannot render.

Source

Thrown at smarttubetv/src/main/java/com/liskovsoft/smartyoutubetv2/tv/ui/dialogs/AppPreferenceManager.java:70

            case OptionCategory.TYPE_CHECKBOX_LIST:
                return createCheckedListPreference(category);
            case OptionCategory.TYPE_RADIO_LIST:
                return createRadioListPreference(category);
            case OptionCategory.TYPE_STRING_LIST:
                return createStringListPreference(category);
            case OptionCategory.TYPE_SINGLE_SWITCH:
                return createSwitchPreference(category);
            case OptionCategory.TYPE_SINGLE_BUTTON:
                return createButtonPreference(category);
            case OptionCategory.TYPE_LONG_TEXT:
                return createLongTextPreference(category);
            case OptionCategory.TYPE_CHAT:
                return createChatPreference(category);
            case OptionCategory.TYPE_COMMENTS:
                return createCommentsPreference(category);
        }

        throw  new IllegalStateException("Can't find matched preference for type: " + category.type);
    }

    private Preference createStringListPreference(OptionCategory category) {
        MultiSelectListPreference pref = new StringListPreference(mContext);

        initMultiSelectListPreference(category, pref);

        return pref;
    }

    private Preference createLongTextPreference(OptionCategory category) {
        MultiSelectListPreference pref = new StringListPreference(mContext);

        pref.setDialogMessage(category.options.get(0).getTitle());

        initMultiSelectListPreference(category, pref);

        return pref;

View on GitHub (pinned to 3de8d90593)

Solutions

  1. Log category.type when the error fires (and the whole category) to learn which value is unhandled.
  2. Add a switch case for the new type with an appropriate createXxxPreference method, or map it to the closest existing type.
  3. If you control OptionCategory, validate type at parse/creation time and substitute a safe default before it reaches the UI.
  4. Ship producer (type constants) and consumer (this switch) in the same change; add a default branch that logs and falls back instead of crashing.

Example fix

// before (AppPreferenceManager)
switch (category.type) {
    case OptionCategory.TYPE_SINGLE_SWITCH: return createSwitchPreference(category);
    // ... no default
}
throw new IllegalStateException("Can't find matched preference for type: " + category.type);

// after — tolerate unknown types instead of crashing the dialog
default:
    Log.w(TAG, "Unknown preference type: " + category.type);
    return createSwitchPreference(category); // or skip this category
Defensive patterns

Strategy: type-guard

Validate before calling

static boolean isSupportedCategoryType(int type) {
    switch (type) {
        case OptionCategory.TYPE_CHECKBOX_LIST:
        case OptionCategory.TYPE_RADIO_LIST:
        case OptionCategory.TYPE_STRING_LIST:
        case OptionCategory.TYPE_SINGLE_SWITCH:
        case OptionCategory.TYPE_SINGLE_BUTTON:
        case OptionCategory.TYPE_LONG_TEXT:
        case OptionCategory.TYPE_CHAT:
        case OptionCategory.TYPE_COMMENTS:
            return true;
        default:
            return false;
    }
}

if (isSupportedCategoryType(category.type)) {
    manager.createPreference(category);
}

Type guard

static boolean isRenderableCategory(OptionCategory c) {
    return c != null && isSupportedCategoryType(c.type);
}

Try / catch

try {
    Preference p = manager.createPreference(category);
} catch (IllegalStateException e) { // Can't find matched preference
    Log.w(TAG, "Skipping unknown option category type: " + category.type, e);
    // skip the category instead of crashing the settings dialog
}

Prevention

When it happens

Trigger: An options payload (player settings, dialogs) contains an OptionCategory with a type constant unknown to this build — a new type added by a newer producer, or a malformed/zero value from deserialized data. Any code path that calls createPreference on such a category throws.

Common situations: Newer options format (server- or model-driven) reaching an older app build; stale serialized state carrying a removed/renamed type constant; tests constructing OptionCategory with a default int type (0) that matches no case; version skew after refactoring the type constants.

Related errors


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