Tencent/matrix · error · XmlPullParserException
No start tag found
Error message
No start tag found
What it means
PowerProfile's XML parsing helper advances the XmlPullParser to the first START_TAG and throws XmlPullParserException("No start tag found") if it reaches END_DOCUMENT first — i.e. the power-profile XML resource is empty or contains only text/comments. This mirrors AOSP's PowerProfile parser and guards against malformed power profile files.
Solutions
- Verify the power-profile XML resource exists and has a valid root element (e.g. <powerprofile> or <device>).
- Re-check the resource id/parser passed to the PowerProfile constructor; ensure it resolves to the intended XML.
- Wrap PowerProfile construction in try-catch for XmlPullParserException and fall back to a bundled default profile.
Example fix
// before
XmlPullParser p = res.getXml(R.xml.maybe_empty_profile);
PowerProfile profile = new PowerProfile(p, "device"); // throws if empty
// after
XmlPullParser p = res.getXml(R.xml.power_profile);
try {
PowerProfile profile = new PowerProfile(p, "device");
} catch (XmlPullParserException e) {
PowerProfile profile = new PowerProfile(res.getXml(R.xml.default_profile), "device");
} Defensive patterns
Strategy: try-catch
Validate before calling
// Verify the resource parses before constructing PowerProfile
XmlPullParser p = res.getXml(R.xml.power_profile);
int t;
while ((t = p.next()) != XmlPullParser.START_TAG && t != XmlPullParser.END_DOCUMENT) {}
if (t == XmlPullParser.END_DOCUMENT) {
// empty resource: use default profile instead
} Try / catch
try {
PowerProfile profile = new PowerProfile(parser, firstElementName);
} catch (XmlPullParserException | IOException e) {
PowerProfile profile = loadDefaultProfile();
} Prevention
- Validate custom power-profile XML files with an XML linter before shipping.
- Ensure the resource id passed to the parser points at a well-formed XML file.
- Test profile loading on the target devices/ROMs where empty streams may occur.
When it happens
Trigger: Constructing a PowerProfile over a power-profile XML (custom com.android.internal.R.xml.power_profile override or a test fixture) whose stream is empty or has no root element, so the parser hits END_DOCUMENT before any START_TAG.
Common situations: Providing a truncated or blank custom power_profile.xml in tests; resource resolution returning an empty stream on certain OEM ROMs; misconfigured XmlResourceParser pointing at a non-XML resource.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- Unexpected start tag: found
- TaskExecuteException wrapping e.getMessage()
- Call #init() first!
- Context should not be null
- Illegal battery state
AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08).
Data as JSON: /api/errors/d37a598938538efe.
Report an issue: GitHub.
Appendix: source
Thrown at matrix/matrix-android/matrix-battery-canary/src/main/java/com/tencent/matrix/batterycanary/utils/PowerProfile.java:661
} else {
return 0;
}
}
public double getBatteryCapacity() {
return getAveragePower(POWER_BATTERY_CAPACITY);
}
@SuppressWarnings("StatementWithEmptyBody")
static class XmlUtils {
public static void beginDocument(XmlPullParser parser, String firstElementName) throws XmlPullParserException, IOException {
int type;
while ((type = parser.next()) != parser.START_TAG
&& type != parser.END_DOCUMENT) {
}
if (type != parser.START_TAG) {
throw new XmlPullParserException("No start tag found");
}
if (!parser.getName().equals(firstElementName)) {
throw new XmlPullParserException("Unexpected start tag: found " + parser.getName() +
", expected " + firstElementName);
}
}
public static void nextElement(XmlPullParser parser) throws XmlPullParserException, IOException {
int type;
while ((type = parser.next()) != parser.START_TAG
&& type != parser.END_DOCUMENT) {
}
}
}
}View on GitHub (pinned to 3b8293bd65)