MuntashirAkon/AppManager · error · IllegalArgumentException
Invalid format: enabled not found
Error message
Invalid format: enabled not found
What it means
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').
Source
Thrown at app/src/main/java/io/github/muntashirakon/AppManager/rules/struct/BatteryOptimizationRule.java:24
import java.util.Objects;
import java.util.StringTokenizer;
import io.github.muntashirakon.AppManager.rules.RuleType;
public class BatteryOptimizationRule extends RuleEntry {
private boolean mEnabled;
public BatteryOptimizationRule(@NonNull String packageName, boolean enabled) {
super(packageName, STUB, RuleType.BATTERY_OPT);
mEnabled = enabled;
}
public BatteryOptimizationRule(@NonNull String packageName, @NonNull StringTokenizer tokenizer) {
super(packageName, STUB, RuleType.BATTERY_OPT);
if (tokenizer.hasMoreElements()) {
mEnabled = Boolean.parseBoolean(tokenizer.nextElement().toString());
} else throw new IllegalArgumentException("Invalid format: enabled not found");
}
public boolean isEnabled() {
return mEnabled;
}
public void setEnabled(boolean enabled) {
mEnabled = enabled;
}
@NonNull
@Override
public String toString() {
return "BatteryOptimizationRule{" +
"packageName='" + packageName + '\'' +
", enabled=" + mEnabled +
'}';
}View on GitHub (pinned to 0152f468fc)
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
Example fix
// before
BatteryOptimizationRule rule = new BatteryOptimizationRule(pkg, new StringTokenizer(line, "\t"));
// after
StringTokenizer st = new StringTokenizer(line, "\t");
if (!st.hasMoreElements()) {
Log.w(TAG, "Skipping malformed battery-opt line: " + line);
return;
}
BatteryOptimizationRule rule = new BatteryOptimizationRule(pkg, st); Defensive patterns
Strategy: validation
Validate before calling
StringTokenizer st = new StringTokenizer(line, "\t");
if (st.countTokens() < 2) { // package + enabled
Log.w(TAG, "Malformed BATTERY_OPT line: " + line);
return;
} Try / catch
try {
rule = new BatteryOptimizationRule(pkg, tokenizer);
} catch (IllegalArgumentException e) {
Log.w(TAG, "Skipping invalid battery-optimization rule: " + line, e);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Truncated rules export files; lines with missing trailing tabs/columns after manual editing; importing rules generated by tools writing a different BATTERY_OPT format.
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
- Invalid format: mode not found
- Invalid format: componentStatus not found
- Failed to load rules from misc.
- Invalid format: Invalid type
- Invalid format: entryType not found
AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12).
Data as JSON: /api/errors/8f3a0db6a18f1547.
Report an issue: GitHub.