{"record":{"id":"c6f4b9bb8a6aeee4","repo":"MuntashirAkon/AppManager","slug":"invalid-attribute-getattributename-index-value","errorCode":null,"errorMessage":"Invalid attribute \" + getAttributeName(index) + \": \" + value","messagePattern":"Invalid attribute \" \\+ getAttributeName\\(index\\) \\+ \": \" \\+ value","errorType":"exception","errorClass":"XmlPullParserException","httpStatus":null,"severity":"error","filePath":"libcore/compat/src/main/java/io/github/muntashirakon/compat/xml/XmlUtils.java","lineNumber":202,"sourceCode":"                throws XmlPullParserException {\n            try {\n                return Double.parseDouble(getAttributeValue(index));\n            } catch (Exception e) {\n                throw new XmlPullParserException(\n                        \"Invalid attribute \" + getAttributeName(index) + \": \" + e);\n            }\n        }\n\n        @Override\n        public boolean getAttributeBoolean(int index)\n                throws XmlPullParserException {\n            final String value = getAttributeValue(index);\n            if (\"true\".equalsIgnoreCase(value)) {\n                return true;\n            } else if (\"false\".equalsIgnoreCase(value)) {\n                return false;\n            } else {\n                throw new XmlPullParserException(\n                        \"Invalid attribute \" + getAttributeName(index) + \": \" + value);\n            }\n        }\n    }\n\n    /**\n     * Return a specialization of the given {@link XmlPullParser} which has\n     * explicit methods to support consistent and efficient conversion of\n     * primitive data types.\n     */\n    public static @NonNull TypedXmlPullParser makeTyped(@NonNull XmlPullParser xml) {\n        if (xml instanceof TypedXmlPullParser) {\n            return (TypedXmlPullParser) xml;\n        } else {\n            return new ForcedTypedXmlPullParser(xml);\n        }\n    }\n","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/compat/src/main/java/io/github/muntashirakon/compat/xml/XmlUtils.java#L184-L220","documentation":"XmlUtils.getAttributeBoolean parses an XML attribute value as a boolean. If the attribute's text is neither \"true\" nor \"false\" (case-insensitive), it throws XmlPullParserException naming the attribute and its raw value. This library mirrors Android's XmlUtils and treats non-boolean attribute values as a hard parse failure rather than returning a default.","triggerScenarios":"Calling getAttributeBoolean(index) (or the name-based overload that resolves to it) on an attribute whose string value is anything other than \"true\"/\"false\" — e.g. \"1\", \"0\", \"yes\", \"\", or a typo like \"ture\".","commonSituations":"Hand-written or third-party XML using 1/0 or yes/no for booleans; attributes edited manually with typos; XML produced by another tool with different boolean conventions.","solutions":["Fix the XML so the attribute value is exactly \"true\" or \"false\" (case-insensitive)","Use getAttributeValue(index) and parse manually with Boolean.parseBoolean or your own mapping when non-standard values must be accepted","Check for typos/whitespace in the attribute value before calling"],"exampleFix":"// before: <package debug=\"1\">\nint flags = XmlUtils.getAttributeBoolean(parser, \"debug\") // throws\n// after\nboolean debug = \"1\".equals(parser.getAttributeValue(null, \"debug\"));\n// or fix XML to <package debug=\"true\">","handlingStrategy":"validation","validationCode":"String v = parser.getAttributeValue(null, \"debug\");\nif (v != null && !\"true\".equalsIgnoreCase(v) && !\"false\".equalsIgnoreCase(v)) {\n    throw new IllegalArgumentException(\"Attribute 'debug' is not a boolean: \" + v);\n}","typeGuard":"boolean isBooleanAttr(String v) {\n    return \"true\".equalsIgnoreCase(v) || \"false\".equalsIgnoreCase(v);\n}","tryCatchPattern":"try {\n    flag = XmlUtils.getAttributeBoolean(parser, index);\n} catch (XmlPullParserException e) {\n    Log.w(TAG, \"Non-boolean attribute, defaulting\", e);\n    flag = false; // or fail-fast depending on strictness\n}","preventionTips":["Author XML with only true/false for boolean attributes","Prefer reading raw attribute values and parsing yourself when accepting 1/0 or yes/no","Validate XML against a schema before parsing"],"tags":["xml","parsing","boolean","attributes"],"backgroundTag":"invalid-argument-value","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"}