{"record":{"id":"d37a598938538efe","repo":"Tencent/matrix","slug":"no-start-tag-found","errorCode":null,"errorMessage":"No start tag found","messagePattern":"No start tag found","errorType":"exception","errorClass":"XmlPullParserException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-battery-canary/src/main/java/com/tencent/matrix/batterycanary/utils/PowerProfile.java","lineNumber":661,"sourceCode":"        } else {\n            return 0;\n        }\n    }\n\n    public double getBatteryCapacity() {\n        return getAveragePower(POWER_BATTERY_CAPACITY);\n    }\n\n    @SuppressWarnings(\"StatementWithEmptyBody\")\n    static class XmlUtils {\n        public static void beginDocument(XmlPullParser parser, String firstElementName) throws XmlPullParserException, IOException {\n            int type;\n            while ((type = parser.next()) != parser.START_TAG\n                    && type != parser.END_DOCUMENT) {\n            }\n\n            if (type != parser.START_TAG) {\n                throw new XmlPullParserException(\"No start tag found\");\n            }\n\n            if (!parser.getName().equals(firstElementName)) {\n                throw new XmlPullParserException(\"Unexpected start tag: found \" + parser.getName() +\n                        \", expected \" + firstElementName);\n            }\n        }\n\n        public static void nextElement(XmlPullParser parser) throws XmlPullParserException, IOException {\n            int type;\n            while ((type = parser.next()) != parser.START_TAG\n                    && type != parser.END_DOCUMENT) {\n            }\n        }\n    }\n}","sourceCodeStart":643,"sourceCodeEnd":677,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-battery-canary/src/main/java/com/tencent/matrix/batterycanary/utils/PowerProfile.java#L643-L677","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nXmlPullParser p = res.getXml(R.xml.maybe_empty_profile);\nPowerProfile profile = new PowerProfile(p, \"device\"); // throws if empty\n\n// after\nXmlPullParser p = res.getXml(R.xml.power_profile);\ntry {\n    PowerProfile profile = new PowerProfile(p, \"device\");\n} catch (XmlPullParserException e) {\n    PowerProfile profile = new PowerProfile(res.getXml(R.xml.default_profile), \"device\");\n}","handlingStrategy":"try-catch","validationCode":"// Verify the resource parses before constructing PowerProfile\nXmlPullParser p = res.getXml(R.xml.power_profile);\nint t;\nwhile ((t = p.next()) != XmlPullParser.START_TAG && t != XmlPullParser.END_DOCUMENT) {}\nif (t == XmlPullParser.END_DOCUMENT) {\n    // empty resource: use default profile instead\n}","typeGuard":null,"tryCatchPattern":"try {\n    PowerProfile profile = new PowerProfile(parser, firstElementName);\n} catch (XmlPullParserException | IOException e) {\n    PowerProfile profile = loadDefaultProfile();\n}","preventionTips":["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."],"tags":["android","xml","parsing","battery"],"backgroundTag":"file-read-failed","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}