MuntashirAkon/AppManager · error · IllegalArgumentException

Package name cannot be empty.

Error message

Package name cannot be empty.

What it means

After parsing (or defaulting) the package name, RuleEntry.unflattenFromString checks it is non-null/empty. If packageName is still null — meaning no package-name token was ever supplied even in internal format — it throws this IllegalArgumentException because a rule entry cannot exist without a package.

Solutions

  1. Pass a flattened string that contains a package name as its first token
  2. Guard with str != null && !str.trim().isEmpty() before parsing
  3. Skip empty lines during batch import
  4. Catch IllegalArgumentException and log the offending line

Example fix

// before
RuleEntry.unflattenFromString("", null); // throws
// after
if (str == null || str.trim().isEmpty()) return null;
RuleEntry.unflattenFromString(str, null);
Defensive patterns

Strategy: validation

Validate before calling

if (str == null || str.trim().isEmpty())
    throw new IllegalArgumentException("Provide a non-empty flattened rule string");

Type guard

boolean isNonEmptyRuleString(String s) { return s != null && !s.trim().isEmpty(); }

Try / catch

try { RuleEntry.unflattenFromString(str, null); } catch (IllegalArgumentException e) { if (e.getMessage().contains("empty")) logSkip(str); }

Prevention

When it happens

Trigger: unflattenFromString called with a string that yields no package name token (e.g. empty string in internal format), or the only token consumed elsewhere so packageName remains null.

Common situations: Blank lines in rules files, calling the parser with an empty String, or stripping the first token before invoking unflattenFromString.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

    @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);
    }

    @NonNull
    private static RuleEntry getRuleEntry(@NonNull String packageName, @NonNull String name,

View on GitHub (pinned to 0152f468fc)