MuntashirAkon/AppManager · error · UnsupportedOperationException

Invalid key ${key}

Error message

Invalid key ${key}

What it means

PackageNameOption.test matches the package name using key-driven logic ('starts_with', 'ends_with', 'regex', etc.). An unrecognized key reaches default and throws UnsupportedOperationException 'Invalid key <key>'. The filter's match-type key is not valid for package-name matching.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/filters/options/PackageNameOption.java:70

                }
                return result.setMatched(false);
            case "eq_none":
                for (String packageName: stringValues) {
                    if (info.getPackageName().equals(packageName)) {
                        return result.setMatched(false);
                    }
                }
                return result.setMatched(true);
            case "contains":
                return result.setMatched(info.getPackageName().contains(Objects.requireNonNull(value)));
            case "starts_with":
                return result.setMatched(info.getPackageName().startsWith(Objects.requireNonNull(value)));
            case "ends_with":
                return result.setMatched(info.getPackageName().endsWith(Objects.requireNonNull(value)));
            case "regex":
                return result.setMatched(regexValue.matcher(info.getPackageName()).matches());
            default:
                throw new UnsupportedOperationException("Invalid key " + key);
        }
    }

    @NonNull
    @Override
    public CharSequence toLocalizedString(@NonNull Context context) {
        SpannableStringBuilder sb = new SpannableStringBuilder("Package name");
        switch (key) {
            case KEY_ALL:
                return sb.append(LangUtils.getSeparatorString()).append("any");
            case "eq":
                return sb.append(" = '").append(value).append("'");
            case "eq_any":
                return sb.append(" matching any of ").append(String.join(", ", stringValues));
            case "eq_none":
                return sb.append(" matching none of ").append(String.join(", ", stringValues));
            case "contains":
                return sb.append(" contains '").append(value).append("'");

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Fix the key to a supported value ('starts_with', 'ends_with', 'regex', etc. as defined by the option).
  2. Re-create the filter in the app UI.
  3. Validate the match-type key when parsing the filter file.
  4. If 'contains' or another match type is genuinely needed, add that case to the switch.

Example fix

// before
new PackageNameOption("package_name", "startswith", "com.example");
// after
new PackageNameOption("package_name", "starts_with", "com.example");
Defensive patterns

Strategy: validation

Validate before calling

Set<String> VALID = Set.of("starts_with", "ends_with", "regex");
if (!VALID.contains(option.getKey())) throw new IllegalArgumentException("Unsupported package_name key: " + option.getKey());

Type guard

boolean isValidKey(String k) { return "starts_with".equals(k) || "ends_with".equals(k) || "regex".equals(k); }

Try / catch

try { matched = option.test(info); } catch (UnsupportedOperationException e) { matched = false; }

Prevention

When it happens

Trigger: Calling test() on a PackageNameOption whose key is not one of the supported match types — e.g. 'contains' misspelled, 'startswith' without underscore, or a key from a different option type.

Common situations: Hand-edited or shared filter JSON with near-miss key names; filters authored against a different app version; copy-paste of keys between filter options with different vocabularies.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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