{"record":{"id":"b109a1283c7ccc5a","repo":"MuntashirAkon/AppManager","slug":"invalid-format-netpolicies-not-found","errorCode":null,"errorMessage":"Invalid format: netPolicies not found","messagePattern":"Invalid format: netPolicies not found","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/rules/struct/NetPolicyRule.java","lineNumber":26,"sourceCode":"import java.util.StringTokenizer;\n\nimport io.github.muntashirakon.AppManager.compat.NetworkPolicyManagerCompat;\nimport io.github.muntashirakon.AppManager.rules.RuleType;\n\npublic class NetPolicyRule extends RuleEntry {\n    @NetworkPolicyManagerCompat.NetPolicy\n    private int mNetPolicies;\n\n    public NetPolicyRule(@NonNull String packageName, @NetworkPolicyManagerCompat.NetPolicy int netPolicies) {\n        super(packageName, STUB, RuleType.NET_POLICY);\n        mNetPolicies = netPolicies;\n    }\n\n    public NetPolicyRule(@NonNull String packageName, @NonNull StringTokenizer tokenizer) {\n        super(packageName, STUB, RuleType.NET_POLICY);\n        if (tokenizer.hasMoreElements()) {\n            mNetPolicies = Integer.parseInt(tokenizer.nextElement().toString());\n        } else throw new IllegalArgumentException(\"Invalid format: netPolicies not found\");\n    }\n\n    @NetworkPolicyManagerCompat.NetPolicy\n    public int getPolicies() {\n        return mNetPolicies;\n    }\n\n    public void setPolicies(@NetworkPolicyManagerCompat.NetPolicy int netPolicies) {\n        mNetPolicies = netPolicies;\n    }\n\n    @NonNull\n    @Override\n    public String toString() {\n        return \"NetPolicyRule{\" +\n                \"packageName='\" + packageName + '\\'' +\n                \", netPolicies=\" + mNetPolicies +\n                '}';","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/rules/struct/NetPolicyRule.java#L8-L44","documentation":"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.","triggerScenarios":"new NetPolicyRule(packageName, tokenizer) invoked with an exhausted tokenizer, i.e. the flattened string has no numeric netPolicies token after the package name.","commonSituations":"Truncated imports, hand-edited rules files where the policies bitmask was deleted, or delimiter changes causing token loss.","solutions":["Include the numeric netPolicies token in the flattened rule string","Verify token count >= 2 before constructing NetPolicyRule","Restore the rule from a complete export file","Catch IllegalArgumentException during import and handle bad lines gracefully"],"exampleFix":"// before\nnew NetPolicyRule(pkg, new StringTokenizer(\"com.example\")); // throws\n// after\nnew NetPolicyRule(pkg, new StringTokenizer(\"com.example\\t4\")); // netPolicies=4","handlingStrategy":"validation","validationCode":"String[] p = line.split(\"\\t\");\nif (p.length < 2) throw new IllegalArgumentException(\"NET_POLICY rule needs netPolicies\");\nInteger.parseInt(p[1]);","typeGuard":"boolean isParsableNetPolicyRule(String line) { String[] p = line.split(\"\\t\"); return p.length >= 2 && p[1].matches(\"\\\\d+\"); }","tryCatchPattern":"try { new NetPolicyRule(pkg, tokenizer); } catch (IllegalArgumentException e) { importer.skip(line, e); }","preventionTips":["Verify the netPolicies bitmask token exists and is numeric before parsing","Don't strip trailing tokens when trimming rule lines","Use AppManager's own flatten() output rather than custom serialization"],"tags":["rules-parsing","netpolicy","illegal-argument"],"backgroundTag":"invalid-argument-format","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}