{"record":{"id":"423bae5130165a17","repo":"MuntashirAkon/AppManager","slug":"invalid-key-key-for-type-type","errorCode":null,"errorMessage":"Invalid key: ${key} for type: ${type}","messagePattern":"Invalid key: (.+?) for type: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOption.java","lineNumber":116,"sourceCode":"    public String getKey() {\n        return key;\n    }\n\n    @KeyType\n    public int getKeyType() {\n        return keyType;\n    }\n\n    @Nullable\n    public String getValue() {\n        return value;\n    }\n\n    @CallSuper\n    public void setKeyValue(@NonNull String key, @Nullable String value) {\n        Integer keyType = getKeysWithType().get(key);\n        if (keyType == null) {\n            throw new IllegalArgumentException(\"Invalid key: \" + key + \" for type: \" + type);\n        }\n        this.key = key;\n        this.keyType = keyType;\n        if (keyType != TYPE_NONE) {\n            this.value = Objects.requireNonNull(value);\n            switch (keyType) {\n                case TYPE_INT:\n                case TYPE_INT_FLAGS:\n                    this.intValue = Integer.parseInt(value);\n                    break;\n                case TYPE_LONG:\n                case TYPE_TIME_MILLIS:\n                case TYPE_DURATION_MILLIS:\n                case TYPE_SIZE_BYTES:\n                    this.longValue = Long.parseLong(value);\n                    break;\n                case TYPE_REGEX:\n                    this.regexValue = Pattern.compile(Pattern.quote(value));","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOption.java#L98-L134","documentation":"FilterOption.setKeyValue() validates that the given key exists in the option's getKeysWithType() map before assigning it. If the key is unknown for this option type, it throws IllegalArgumentException. This guards against deserializing or programmatically constructing a filter option with a key that the concrete option class does not support.","triggerScenarios":"Calling setKeyValue(key, value) with a key not present in the concrete option's getKeysWithType() map; deserializing a Parcel in createFromParcel() or JSON in fromJson() where the stored key no longer matches the option's key set (e.g. key renamed/removed in an app update, or key from a different option type).","commonSituations":"Restoring an old saved filter/JSON after a version change renamed or dropped a key; a typo in the key string; pairing a key with the wrong option type (e.g. passing \"before\" to a freeze option instead of a last-update option).","solutions":["Check the key against the option's getKeysWithType().keySet() before calling setKeyValue and fix the typo/mismatch.","Verify the option type matches the key: create the option via FilterOptions.create(type) using the same type the key belongs to.","If migrating old persisted filters, map or drop obsolete keys before deserialization."],"exampleFix":"// before\noption.setKeyValue(\"befor\", value);\n// after\noption.setKeyValue(\"before\", value);","handlingStrategy":"validation","validationCode":"if (option.getKeysWithType().containsKey(key)) {\n    option.setKeyValue(key, value);\n} else {\n    throw new IllegalArgumentException(\"Unsupported key \" + key + \" for \" + option.type);\n}","typeGuard":"boolean isValidKey(FilterOption o, String key) { return key != null && o.getKeysWithType().containsKey(key); }","tryCatchPattern":"try {\n    option.setKeyValue(key, value);\n} catch (IllegalArgumentException e) {\n    Log.w(TAG, \"Skipping invalid filter key\", e);\n}","preventionTips":["Always validate keys against getKeysWithType() before calling setKeyValue.","Derive keys from constants (e.g. KEY_ALL) instead of raw string literals.","When migrating persisted filters, whitelist known keys and drop the rest."],"tags":["java","android","validation","illegal-argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}