{"record":{"id":"8f3a0db6a18f1547","repo":"MuntashirAkon/AppManager","slug":"invalid-format-enabled-not-found","errorCode":null,"errorMessage":"Invalid format: enabled not found","messagePattern":"Invalid format: enabled not found","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/rules/struct/BatteryOptimizationRule.java","lineNumber":24,"sourceCode":"\nimport java.util.Objects;\nimport java.util.StringTokenizer;\n\nimport io.github.muntashirakon.AppManager.rules.RuleType;\n\npublic class BatteryOptimizationRule extends RuleEntry {\n    private boolean mEnabled;\n\n    public BatteryOptimizationRule(@NonNull String packageName, boolean enabled) {\n        super(packageName, STUB, RuleType.BATTERY_OPT);\n        mEnabled = enabled;\n    }\n\n    public BatteryOptimizationRule(@NonNull String packageName, @NonNull StringTokenizer tokenizer) {\n        super(packageName, STUB, RuleType.BATTERY_OPT);\n        if (tokenizer.hasMoreElements()) {\n            mEnabled = Boolean.parseBoolean(tokenizer.nextElement().toString());\n        } else throw new IllegalArgumentException(\"Invalid format: enabled not found\");\n    }\n\n    public boolean isEnabled() {\n        return mEnabled;\n    }\n\n    public void setEnabled(boolean enabled) {\n        mEnabled = enabled;\n    }\n\n    @NonNull\n    @Override\n    public String toString() {\n        return \"BatteryOptimizationRule{\" +\n                \"packageName='\" + packageName + '\\'' +\n                \", enabled=\" + mEnabled +\n                '}';\n    }","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/rules/struct/BatteryOptimizationRule.java#L6-L42","documentation":"BatteryOptimizationRule parses a TSV rule line whose only payload field is the enabled flag. If the StringTokenizer has no next element, the line lacks the enabled field, and the constructor throws IllegalArgumentException('Invalid format: enabled not found').","triggerScenarios":"new BatteryOptimizationRule(pkg, tokenizer) where the tokenizer is empty or exhausted after the constructor consumed nothing — i.e. a BATTERY_OPT line without the boolean column.","commonSituations":"Truncated rules export files; lines with missing trailing tabs/columns after manual editing; importing rules generated by tools writing a different BATTERY_OPT format.","solutions":["Ensure each battery-optimization rule line includes the enabled boolean column (e.g. pkg<TAB>true)","Check tokenizer.hasMoreElements() and skip/log the line instead of constructing the rule","Re-export the rules file from the current app version to restore the correct format"],"exampleFix":"// before\nBatteryOptimizationRule rule = new BatteryOptimizationRule(pkg, new StringTokenizer(line, \"\\t\"));\n// after\nStringTokenizer st = new StringTokenizer(line, \"\\t\");\nif (!st.hasMoreElements()) {\n    Log.w(TAG, \"Skipping malformed battery-opt line: \" + line);\n    return;\n}\nBatteryOptimizationRule rule = new BatteryOptimizationRule(pkg, st);","handlingStrategy":"validation","validationCode":"StringTokenizer st = new StringTokenizer(line, \"\\t\");\nif (st.countTokens() < 2) { // package + enabled\n    Log.w(TAG, \"Malformed BATTERY_OPT line: \" + line);\n    return;\n}","typeGuard":null,"tryCatchPattern":"try {\n    rule = new BatteryOptimizationRule(pkg, tokenizer);\n} catch (IllegalArgumentException e) {\n    Log.w(TAG, \"Skipping invalid battery-optimization rule: \" + line, e);\n}","preventionTips":["Check tokenizer.hasMoreElements() before constructing rule objects","Re-export rules rather than editing the TSV by hand","Validate line format when importing files from unknown sources"],"tags":["parsing","tsv","rules","format"],"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-14T16:17:12.679Z"}