MuntashirAkon/AppManager · error · UnsupportedOperationException

Invalid key ${key}

Error message

Invalid key ${key}

What it means

RunningAppsOption.test classifies apps by switching on key ('running', 'not_running', plus an always-match case). An unrecognized key reaches default and throws UnsupportedOperationException 'Invalid key <key>'. The option got a state key it does not implement.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/filters/options/RunningAppsOption.java:43

    @NonNull
    @Override
    public Map<String, Integer> getKeysWithType() {
        return mKeysWithType;
    }

    @NonNull
    @Override
    public TestResult test(@NonNull IFilterableAppInfo info, @NonNull TestResult result) {
        switch (key) {
            case KEY_ALL:
                return result.setMatched(true);
            case "running":
                return result.setMatched(info.isRunning());
            case "not_running":
                return result.setMatched(!info.isRunning());
            default:
                throw new UnsupportedOperationException("Invalid key " + key);
        }
    }

    @NonNull
    @Override
    public CharSequence toLocalizedString(@NonNull Context context) {
        SpannableStringBuilder sb = new SpannableStringBuilder("App label");
        switch (key) {
            case KEY_ALL:
                return "Both running and not running apps";
            case "running":
                return "Only the running apps";
            case "not_running":
                return "Only the not running apps";
            default:
                throw new UnsupportedOperationException("Invalid key " + key);
        }
    }

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Change the key to 'running' or 'not_running'.
  2. Re-create the filter in the UI.
  3. Validate the key at option construction.
  4. Add the missing case if a new mode is needed.

Example fix

// before
new RunningAppsOption("running_apps", "is_running");
// after
new RunningAppsOption("running_apps", "running");
Defensive patterns

Strategy: validation

Validate before calling

if (!("running".equals(k) || "not_running".equals(k))) throw new IllegalArgumentException("Unsupported running_apps key: " + k);

Type guard

boolean isValidKey(String k) { return "running".equals(k) || "not_running".equals(k); }

Try / catch

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

Prevention

When it happens

Trigger: Calling test() on a RunningAppsOption whose key is not exactly 'running' or 'not_running' (or the both-case sentinel) — e.g. 'is_running' from a typo or another option's vocabulary.

Common situations: Edited filter JSON; key sets drifting between app versions; building filters programmatically with guessed key names.

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/213b2044ad9f8595. Report an issue: GitHub.