MuntashirAkon/AppManager · error · IllegalArgumentException

Invalid format: packageName not found for external rule.

Error message

Invalid format: packageName not found for external rule.

What it means

RuleEntry.unflattenFromString, when parsing the external-rule format (marked by a leading delimiter), requires the first token to be the package name. If the tokenizer is exhausted at that point, it throws this IllegalArgumentException because an external rule cannot be parsed without a package name.

Solutions

  1. Provide a non-empty flattened string beginning with the package name
  2. Skip empty/blank lines before calling unflattenFromString
  3. Check tokenizer.hasMoreElements() before parsing external rules
  4. Catch IllegalArgumentException and treat the line as invalid import data

Example fix

// before
RuleEntry.unflattenFromString("\t", null); // throws: no packageName token
// after
if (str != null && str.trim().length() > 1) RuleEntry.unflattenFromString(str, null);
Defensive patterns

Strategy: validation

Validate before calling

if (line == null || line.trim().isEmpty()) return;
String[] p = line.split("\t");
if (p.length < 1 || p[0].isEmpty()) throw new IllegalArgumentException("external rule needs packageName");

Type guard

boolean hasPackageName(String line) { String[] p = line.trim().split("\t"); return p.length >= 1 && !p[0].isEmpty(); }

Try / catch

try { RuleEntry.unflattenFromString(line, null); } catch (IllegalArgumentException e) { if (e.getMessage().contains("packageName")) skipBlank(line); }

Prevention

When it happens

Trigger: Calling unflattenFromString (or a subclass factory) on an external-format string whose token list is empty after the initial delimiter, e.g. an empty or delimiter-only string.

Common situations: Empty lines in an imported rules file, strings containing only the external-rule marker, or split operations producing zero tokens.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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

Appendix: source

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

    protected String addPackageWithTab(boolean isExternal) {
        return (isExternal ? packageName + "\t" : "");
    }

    @NonNull
    public static RuleEntry unflattenFromString(@Nullable String packageName, @NonNull String ruleLine,
                                                boolean isExternal) throws IllegalArgumentException {
        StringTokenizer tokenizer = new StringTokenizer(ruleLine, "\t");
        if (isExternal) {
            // External rules, the first part is the package name
            if (tokenizer.hasMoreElements()) {
                // Match package name
                String newPackageName = tokenizer.nextElement().toString();
                if (packageName == null) packageName = newPackageName;
                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);

View on GitHub (pinned to 0152f468fc)