MuntashirAkon/AppManager · error · IllegalArgumentException

Invalid format: netPolicies not found

Error message

Invalid format: netPolicies not found

What it means

NetPolicyRule's constructor reads the netPolicies integer (a bitmask of NetworkPolicyManager flags) from the flattened rule string. If the tokenizer has no tokens left, it throws this IllegalArgumentException because a NET_POLICY rule is meaningless without its policies value.

Solutions

  1. Include the numeric netPolicies token in the flattened rule string
  2. Verify token count >= 2 before constructing NetPolicyRule
  3. Restore the rule from a complete export file
  4. Catch IllegalArgumentException during import and handle bad lines gracefully

Example fix

// before
new NetPolicyRule(pkg, new StringTokenizer("com.example")); // throws
// after
new NetPolicyRule(pkg, new StringTokenizer("com.example\t4")); // netPolicies=4
Defensive patterns

Strategy: validation

Validate before calling

String[] p = line.split("\t");
if (p.length < 2) throw new IllegalArgumentException("NET_POLICY rule needs netPolicies");
Integer.parseInt(p[1]);

Type guard

boolean isParsableNetPolicyRule(String line) { String[] p = line.split("\t"); return p.length >= 2 && p[1].matches("\\d+"); }

Try / catch

try { new NetPolicyRule(pkg, tokenizer); } catch (IllegalArgumentException e) { importer.skip(line, e); }

Prevention

When it happens

Trigger: new NetPolicyRule(packageName, tokenizer) invoked with an exhausted tokenizer, i.e. the flattened string has no numeric netPolicies token after the package name.

Common situations: Truncated imports, hand-edited rules files where the policies bitmask was deleted, or delimiter changes causing token loss.

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

Appendix: source

Thrown at app/src/main/java/io/github/muntashirakon/AppManager/rules/struct/NetPolicyRule.java:26

import java.util.StringTokenizer;

import io.github.muntashirakon.AppManager.compat.NetworkPolicyManagerCompat;
import io.github.muntashirakon.AppManager.rules.RuleType;

public class NetPolicyRule extends RuleEntry {
    @NetworkPolicyManagerCompat.NetPolicy
    private int mNetPolicies;

    public NetPolicyRule(@NonNull String packageName, @NetworkPolicyManagerCompat.NetPolicy int netPolicies) {
        super(packageName, STUB, RuleType.NET_POLICY);
        mNetPolicies = netPolicies;
    }

    public NetPolicyRule(@NonNull String packageName, @NonNull StringTokenizer tokenizer) {
        super(packageName, STUB, RuleType.NET_POLICY);
        if (tokenizer.hasMoreElements()) {
            mNetPolicies = Integer.parseInt(tokenizer.nextElement().toString());
        } else throw new IllegalArgumentException("Invalid format: netPolicies not found");
    }

    @NetworkPolicyManagerCompat.NetPolicy
    public int getPolicies() {
        return mNetPolicies;
    }

    public void setPolicies(@NetworkPolicyManagerCompat.NetPolicy int netPolicies) {
        mNetPolicies = netPolicies;
    }

    @NonNull
    @Override
    public String toString() {
        return "NetPolicyRule{" +
                "packageName='" + packageName + '\'' +
                ", netPolicies=" + mNetPolicies +
                '}';

View on GitHub (pinned to 0152f468fc)