MuntashirAkon/AppManager · error · IllegalArgumentException

Invalid key: for type

Error message

Invalid key: ${key} for type: ${type}

What it means

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.

Solutions

  1. Check the key against the option's getKeysWithType().keySet() before calling setKeyValue and fix the typo/mismatch.
  2. Verify the option type matches the key: create the option via FilterOptions.create(type) using the same type the key belongs to.
  3. If migrating old persisted filters, map or drop obsolete keys before deserialization.

Example fix

// before
option.setKeyValue("befor", value);
// after
option.setKeyValue("before", value);
Defensive patterns

Strategy: validation

Validate before calling

if (option.getKeysWithType().containsKey(key)) {
    option.setKeyValue(key, value);
} else {
    throw new IllegalArgumentException("Unsupported key " + key + " for " + option.type);
}

Type guard

boolean isValidKey(FilterOption o, String key) { return key != null && o.getKeysWithType().containsKey(key); }

Try / catch

try {
    option.setKeyValue(key, value);
} catch (IllegalArgumentException e) {
    Log.w(TAG, "Skipping invalid filter key", e);
}

Prevention

When it happens

Trigger: 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).

Common situations: 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).

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/423bae5130165a17. Report an issue: GitHub.

Appendix: source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/filters/options/FilterOption.java:116

    public String getKey() {
        return key;
    }

    @KeyType
    public int getKeyType() {
        return keyType;
    }

    @Nullable
    public String getValue() {
        return value;
    }

    @CallSuper
    public void setKeyValue(@NonNull String key, @Nullable String value) {
        Integer keyType = getKeysWithType().get(key);
        if (keyType == null) {
            throw new IllegalArgumentException("Invalid key: " + key + " for type: " + type);
        }
        this.key = key;
        this.keyType = keyType;
        if (keyType != TYPE_NONE) {
            this.value = Objects.requireNonNull(value);
            switch (keyType) {
                case TYPE_INT:
                case TYPE_INT_FLAGS:
                    this.intValue = Integer.parseInt(value);
                    break;
                case TYPE_LONG:
                case TYPE_TIME_MILLIS:
                case TYPE_DURATION_MILLIS:
                case TYPE_SIZE_BYTES:
                    this.longValue = Long.parseLong(value);
                    break;
                case TYPE_REGEX:
                    this.regexValue = Pattern.compile(Pattern.quote(value));

View on GitHub (pinned to 0152f468fc)