{"record":{"id":"c821af258a818453","repo":"MuntashirAkon/AppManager","slug":"invalid-tag-tagname","errorCode":null,"errorMessage":"Invalid tag: ${tagName}","messagePattern":"Invalid tag: (.+?)","errorType":"validation","errorClass":"org.xmlpull.v1.XmlPullParserException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/github/muntashirakon/AppManager/sharedpref/SharedPrefsUtil.java","lineNumber":93,"sourceCode":"                    case TAG_SET:\n                        Set<String> stringSet = new HashSet<>();\n                        prefs.put(attrName, stringSet);\n                        // Grab all strings\n                        event = parser.next();\n                        tagName = parser.getName();\n                        while (event != XmlPullParser.END_TAG || !Objects.equals(tagName, TAG_SET)) {\n                            if (event == XmlPullParser.START_TAG) {\n                                if (!Objects.equals(tagName, TAG_STRING)) {\n                                    throw new XmlPullParserException(\"Invalid tag inside <set>: \" + tagName);\n                                }\n                                stringSet.add(parser.nextText());\n                            }\n                            event = parser.next();\n                            tagName = parser.getName();\n                        }\n                        break;\n                    default:\n                        throw new XmlPullParserException(\"Invalid tag: \" + tagName);\n                }\n            }\n            event = parser.next();\n        }\n        return prefs;\n    }\n\n    public static void writeSharedPref(@NonNull OutputStream os, @NonNull Map<String, Object> hashMap)\n            throws IOException {\n        XmlSerializer xmlSerializer = Xml.newSerializer();\n        StringWriter stringWriter = new StringWriter();\n        xmlSerializer.setOutput(stringWriter);\n        xmlSerializer.startDocument(\"UTF-8\", true);\n        xmlSerializer.startTag(\"\", TAG_ROOT);\n        // Add values\n        for (String name : hashMap.keySet()) {\n            Object value = hashMap.get(name);\n            if (value instanceof Boolean) {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/app/src/main/java/io/github/muntashirakon/AppManager/sharedpref/SharedPrefsUtil.java#L75-L111","documentation":"XmlPullParserException thrown by SharedPrefsUtil.readSharedPref when the XML parser encounters an element tag that is not one of the recognized shared-preference tags (string, set, etc.) while reading a preferences file. The utility expects a well-formed Android SharedPreferences XML export; any unknown element makes the structure ambiguous, so parsing is aborted rather than silently skipping data.","triggerScenarios":"Calling readSharedPref on an XML file whose <map> body contains an element type not handled by the parser's switch statement (e.g. <int>, <long>, <boolean>, <float> from a standard Android prefs export, or arbitrary/renamed tags from a hand-edited or third-party generated file); tagName is read from parser.getName() at each iteration and falls through to the default branch.","commonSituations":"Restoring preferences exported from a different tool or Android version that wrote numeric/boolean pref types which this util does not support; hand-editing the XML and introducing a typo in a tag name; concatenating XML from multiple sources.","solutions":["Add handling for the unsupported tag types (int, long, boolean, float) in the parser's switch statement before the default branch","Inspect the file being parsed and remove/convert the unrecognized element to a supported type (e.g. stringify ints/booleans)","Regenerate the XML using App Manager's own export so only supported tags are present","Wrap the readSharedPref call in a try-catch for XmlPullParserException and fall back to a partial/default prefs map"],"exampleFix":"// before\ndefault:\n    throw new XmlPullParserException(\"Invalid tag: \" + tagName);\n// after\ncase \"int\":\n    prefs.put(tagName, String.valueOf(Integer.parseInt(parser.nextText())));\n    break;\ncase \"boolean\":\n    prefs.put(tagName, parser.nextText());\n    break;\ndefault:\n    throw new XmlPullParserException(\"Invalid tag: \" + tagName);","handlingStrategy":"validation","validationCode":"Set<String> allowed = Set.of(\"string\", \"string-set\", \"set\", rootTag);\nboolean parseable = doc.getRootElement().getChildNodes().stream()\n    .allMatch(n -> allowed.contains(n.getNodeName()));\nif (!parseable) throw new IllegalArgumentException(\"Unsupported pref tag in XML\");","typeGuard":"boolean isSupportedTag(String tag) {\n    return \"string\".equals(tag) || \"set\".equals(tag) || \"string-set\".equals(tag);\n}","tryCatchPattern":"try {\n    prefs = SharedPrefsUtil.readSharedPref(xmlFile);\n} catch (XmlPullParserException e) {\n    Log.w(TAG, \"Unrecognized pref tag: \" + e.getMessage(), e);\n    prefs = Collections.emptyMap();\n}","preventionTips":["Only parse XML files produced by App Manager's own export","Pre-convert numeric/boolean prefs to strings before import","Sanity-check tag names with xmllint or a quick scan before parsing","Log the offending tag name to speed up extending the parser"],"tags":["xml","parsing","sharedpreferences"],"backgroundTag":"schema-validation-failed","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}