MuntashirAkon/AppManager · error · UnsupportedOperationException
Invalid key ${key}
Error message
Invalid key ${key} What it means
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().
Source
Thrown at app/src/main/java/io/github/muntashirakon/AppManager/filters/options/AppTypeOption.java:127
return result.setMatched(withoutFlagsCheck(info, intValue));
default:
throw new UnsupportedOperationException("Invalid key " + key);
}
}
@NonNull
@Override
public CharSequence toLocalizedString(@NonNull Context context) {
SpannableStringBuilder sb = new SpannableStringBuilder("Apps");
switch (key) {
case KEY_ALL:
return sb.append(LangUtils.getSeparatorString()).append("any");
case "with_flags":
return sb.append(" with flags: ").append(flagsToString("with_flags", intValue));
case "without_flags":
return sb.append(" without flags: ").append(flagsToString("without_flags", intValue));
default:
throw new UnsupportedOperationException("Invalid key " + key);
}
}
/**
* Returns true if the given info matches all the flags in 'flag'.
* Only checks those flags that are set in 'flag' to minimize expensive calls.
*/
public static boolean withFlagsCheck(IFilterableAppInfo info, int flag) {
if ((flag & AppTypeOption.APP_TYPE_SYSTEM) != 0) {
if (!info.isSystemApp()) return false;
}
if ((flag & AppTypeOption.APP_TYPE_USER) != 0) {
if (info.isSystemApp()) return false;
}
if ((flag & AppTypeOption.APP_TYPE_UPDATED_SYSTEM) != 0) {
if (!info.isUpdatedSystemApp()) return false;
}
if ((flag & AppTypeOption.APP_TYPE_PRIVILEGED) != 0) {View on GitHub (pinned to 0152f468fc)
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
Example fix
// before
FilterOption option = new AppTypeOption("app_type", "typo_key");
CharSequence label = option.toLocalizedString(context); // throws
// after
String key = "with_flags"; // must be a key AppTypeOption handles
FilterOption option = new AppTypeOption("app_type", key);
CharSequence label = option.toLocalizedString(context); Defensive patterns
Strategy: type-guard
Validate before calling
Set<String> VALID = Set.of("any","with_flags","without_flags"); if (!VALID.contains(key)) throw new IllegalArgumentException("Unsupported AppTypeOption key: " + key); Type guard
boolean isValidAppTypeKey(String key) { return key != null && (key.equals("any") || key.equals("with_flags") || key.equals("without_flags")); } Try / catch
try { CharSequence label = option.toLocalizedString(context); } catch (UnsupportedOperationException e) { label = option.getKey(); /* graceful fallback for unknown keys */ } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/0641c223f9bd1a51.
Report an issue: GitHub.