MuntashirAkon/AppManager · error · IllegalArgumentException

Invalid format: Invalid type

Error message

Invalid format: Invalid type

What it means

RuleEntry.unflattenFromString parses a tab-separated rule line and converts the third token into a RuleType via RuleType.valueOf. If that token is not a valid RuleType constant name, valueOf throws and the parser rethrows IllegalArgumentException("Invalid format: Invalid type"). This guards against corrupt or hand-edited rule lines whose entry type field is unrecognizable.

Source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/rules/struct/RuleEntry.java:84

                if (!packageName.equals(newPackageName)) {
                    throw new IllegalArgumentException("Invalid format: package names do not match.");
                }
            } else throw new IllegalArgumentException("Invalid format: packageName not found for external rule.");
        }
        if (packageName == null) {
            // packageName can't be empty
            throw new IllegalArgumentException("Package name cannot be empty.");
        }
        String name;
        RuleType type;
        if (tokenizer.hasMoreElements()) {
            name = tokenizer.nextElement().toString();
        } else throw new IllegalArgumentException("Invalid format: name not found");
        if (tokenizer.hasMoreElements()) {
            try {
                type = RuleType.valueOf(tokenizer.nextElement().toString());
            } catch (Exception e) {
                throw new IllegalArgumentException("Invalid format: Invalid type");
            }
        } else throw new IllegalArgumentException("Invalid format: entryType not found");
        return getRuleEntry(packageName, name, type, tokenizer);
    }

    @NonNull
    private static RuleEntry getRuleEntry(@NonNull String packageName, @NonNull String name,
                                          @NonNull RuleType type, @NonNull StringTokenizer tokenizer)
            throws IllegalArgumentException {
        switch (type) {
            case ACTIVITY:
            case PROVIDER:
            case RECEIVER:
            case SERVICE:
                return new ComponentRule(packageName, name, type, tokenizer);
            case APP_OP:
                return new AppOpRule(packageName, name, tokenizer);
            case PERMISSION:

View on GitHub (pinned to 0152f468fc)

Solutions

  1. Print the offending rule line and fix the third field to an exact uppercase RuleType name (e.g. ACTIVITY, APP_OP).
  2. Re-export the rules from the App Manager version that produced them, or upgrade App Manager so its RuleType covers the type string.
  3. Pre-validate lines with a try/catch around RuleType.valueOf(token) or RuleType.values() lookup before parsing.
  4. Ensure fields are separated by literal tab characters and there are no accidental empty fields.

Example fix

// before
RuleEntry entry = RuleEntry.unflattenFromString(pkg, line, true);
// after
String[] parts = line.split("\t");
try {
    RuleType.valueOf(parts[parts.length - 1].trim()); // or check known names first
    RuleEntry entry = RuleEntry.unflattenFromString(pkg, line, true);
} catch (IllegalArgumentException e) {
    Log.w(TAG, "Skipping malformed rule: " + line);
}
Defensive patterns

Strategy: validation

Validate before calling

boolean isValidType(String token) {
    for (RuleType t : RuleType.values()) {
        if (t.name().equals(token)) return true;
    }
    return false;
}
// call only if isValidType(line.split("\t")[2])

Type guard

RuleType safeValueOf(String s) {
    try { return RuleType.valueOf(s); } catch (IllegalArgumentException e) { return null; }
}

Try / catch

try {
    RuleEntry e = RuleEntry.unflattenFromString(pkg, line, isExternal);
} catch (IllegalArgumentException e) {
    Log.w(TAG, "Skipping malformed rule: " + line);
}

Prevention

When it happens

Trigger: Calling RuleEntry.unflattenFromString(packageName, ruleLine, isExternal) with a ruleLine whose third tab-separated token is not an exact RuleType enum name (e.g. 'component' instead of 'COMPONENT', misspelled or renamed type, empty token between two tabs).

Common situations: Importing external rules exported by a different App Manager version whose RuleType set differs; hand-editing or truncating a rules.txt; case-sensitivity mistakes since valueOf is case-sensitive; non-tab whitespace separators.

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/8cfe90ba0dd0c927. Report an issue: GitHub.