{"record":{"id":"0641c223f9bd1a51","repo":"MuntashirAkon/AppManager","slug":"invalid-key-key","errorCode":null,"errorMessage":"Invalid key ${key}","messagePattern":"Invalid key (.+?)","errorType":"validation","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/filters/options/AppTypeOption.java","lineNumber":127,"sourceCode":"                return result.setMatched(withoutFlagsCheck(info, intValue));\n            default:\n                throw new UnsupportedOperationException(\"Invalid key \" + key);\n        }\n    }\n\n    @NonNull\n    @Override\n    public CharSequence toLocalizedString(@NonNull Context context) {\n        SpannableStringBuilder sb = new SpannableStringBuilder(\"Apps\");\n        switch (key) {\n            case KEY_ALL:\n                return sb.append(LangUtils.getSeparatorString()).append(\"any\");\n            case \"with_flags\":\n                return sb.append(\" with flags: \").append(flagsToString(\"with_flags\", intValue));\n            case \"without_flags\":\n                return sb.append(\" without flags: \").append(flagsToString(\"without_flags\", intValue));\n            default:\n                throw new UnsupportedOperationException(\"Invalid key \" + key);\n        }\n    }\n\n    /**\n     * Returns true if the given info matches all the flags in 'flag'.\n     * Only checks those flags that are set in 'flag' to minimize expensive calls.\n     */\n    public static boolean withFlagsCheck(IFilterableAppInfo info, int flag) {\n        if ((flag & AppTypeOption.APP_TYPE_SYSTEM) != 0) {\n            if (!info.isSystemApp()) return false;\n        }\n        if ((flag & AppTypeOption.APP_TYPE_USER) != 0) {\n            if (info.isSystemApp()) return false;\n        }\n        if ((flag & AppTypeOption.APP_TYPE_UPDATED_SYSTEM) != 0) {\n            if (!info.isUpdatedSystemApp()) return false;\n        }\n        if ((flag & AppTypeOption.APP_TYPE_PRIVILEGED) != 0) {","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/AppTypeOption.java#L109-L145","documentation":"AppTypeOption.toLocalizedString() maps a filter key (case string) to a human-readable description; any key outside its known set falls through to default and throws UnsupportedOperationException(\"Invalid key \" + key). This is an internal contract check: the key must be one the option also accepts in test().","triggerScenarios":"Calling toLocalizedString() on an AppTypeOption whose key is not one of the handled cases (e.g. a typo like \"types\" or a key added to the option family but not this subclass), typically from generic filter-UI code that builds strings for arbitrary keys.","commonSituations":"Renaming/adding filter keys in one class but not updating toLocalizedString; persistence files (old saved filters) containing keys from an older schema; reflection- or data-driven UI passing wrong keys.","solutions":["Ensure the key passed to the AppTypeOption constructor matches exactly one of the switch cases (e.g. \"with_flags\", \"without_flags\")","Update toLocalizedString()'s switch to handle any newly added key for this option","Migrate or discard saved filter configs that contain obsolete keys","Wrap generic string-building code in a check that the key is supported before calling"],"exampleFix":"// before\nFilterOption option = new AppTypeOption(\"app_type\", \"typo_key\");\nCharSequence label = option.toLocalizedString(context); // throws\n// after\nString key = \"with_flags\"; // must be a key AppTypeOption handles\nFilterOption option = new AppTypeOption(\"app_type\", key);\nCharSequence label = option.toLocalizedString(context);","handlingStrategy":"type-guard","validationCode":"Set<String> VALID = Set.of(\"any\",\"with_flags\",\"without_flags\"); if (!VALID.contains(key)) throw new IllegalArgumentException(\"Unsupported AppTypeOption key: \" + key);","typeGuard":"boolean isValidAppTypeKey(String key) { return key != null && (key.equals(\"any\") || key.equals(\"with_flags\") || key.equals(\"without_flags\")); }","tryCatchPattern":"try { CharSequence label = option.toLocalizedString(context); } catch (UnsupportedOperationException e) { label = option.getKey(); /* graceful fallback for unknown keys */ }","preventionTips":["Define key constants in one place and reuse them in constructors and switches","Keep test() and toLocalizedString() switch cases in sync when adding keys","Version-check and migrate saved filter configs","Add unit tests that localize every supported key"],"tags":["android","filters","localization","unsupported-key"],"backgroundTag":"unsupported-operation","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}