{"record":{"id":"6a5849b03fb02b1e","repo":"Tencent/matrix","slug":"could-not-decode-xml-var7-getmessage","errorCode":null,"errorMessage":"Could not decode XML,<var7.getMessage()>","messagePattern":"Could not decode XML,<var7\\.getMessage\\(\\)>","errorType":"exception","errorClass":"AndrolibException","httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-apk-canary/src/main/java/com/tencent/matrix/apk/model/task/util/XmlPullResourceRefDecoder.java","lineNumber":69,"sourceCode":"            mParser.setInput(inputStream, null);\n            int token = mParser.next();\n            while (token != XmlPullParser.END_DOCUMENT) {\n                switch (token) {\n                    case XmlPullParser.START_TAG:\n                        handleElement();\n                        break;\n                    case XmlPullParser.TEXT:\n                        handleContent();\n                        break;\n                    default:\n                        break;\n                }\n                token = mParser.next();\n            }\n//            Log.i(TAG, \"find resource references: %s\", resourceRefSet);\n            inputStream.close();\n        } catch (XmlPullParserException var7) {\n            throw new AndrolibException(\"Could not decode XML,\" + var7.getMessage(), var7);\n        } catch (IOException e) {\n            throw new AndrolibException(\"Parse xml error,\" + e.getMessage(), e);\n        }\n    }\n\n    private void handleElement() {\n        String tagName = mParser.getName();\n        int pointIndex = tagName.lastIndexOf('.');\n        if (pointIndex >= 0) {\n            tagName = tagName.substring(pointIndex + 1);\n        }\n        if (!Util.isNullOrNil(tagName)) {\n            for (int i = 0; i < mParser.getAttributeCount(); i++) {\n                String value = mParser.getAttributeValue(i);\n                //Log.d(TAG, \"attribute %s, %s\", name, value);\n                if (!Util.isNullOrNil(value)) {\n                    if (value.startsWith(\"@\")) {\n                        int index = value.indexOf('/');","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-apk-canary/src/main/java/com/tencent/matrix/apk/model/task/util/XmlPullResourceRefDecoder.java#L51-L87","documentation":"XmlPullResourceRefDecoder.decode() parses Android binary/resource XML with an XmlPullParser; on XmlPullParserException it wraps the failure in AndrolibException(\"Could not decode XML,...\"). Called from decodeResResource, decodeResValues and decodeResourcesRef when decoding the compiled resource XML inside the APK.","triggerScenarios":"Feeding a malformed, non-binary, or truncated XML stream (e.g. plain-text XML where compiled binary XML is expected, or AAPT2-obfuscated resources) into decode via UnzipTask's resource analysis.","commonSituations":"Analyzing APKs built with resource obfuscation/packers (e.g. AndResGuard variants) that alter binary XML structure; truncated extraction due to disk issues; hand-modified resource files.","solutions":["Inspect var7.getMessage() in the AndrolibException cause for the parse position and token type.","Analyze an APK built without resource obfuscation, or supply the matching resguard mapping so names decode correctly.","Verify the extracted XML files are complete (re-unzip to a clean directory) and match the target SDK's binary XML format."],"exampleFix":"// before\n// analyzing an AndResGuard-processed APK with default decoder config\n// after\nconfig.setResMappingFilePath(\"build/resguard/resguard-mapping.txt\"); // enable proper decoding","handlingStrategy":"try-catch","validationCode":"// ensure the APK entry to decode exists and is non-empty\nZipEntry entry = zipFile.getEntry(\"AndroidManifest.xml\");\nif (entry == null || entry.getSize() == 0) {\n    throw new IllegalStateException(\"Required XML entry missing or empty\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    decoder.decode(inputStream);\n} catch (AndrolibException e) {\n    if (e.getMessage().startsWith(\"Could not decode XML\")) {\n        logger.error(\"Binary XML decode failed (possibly obfuscated resources): \" + e.getMessage(), e.getCause());\n    } else throw e;\n}","preventionTips":["Don't feed non-binary (plain-text) XML streams into the decoder.","Provide the matching resguard/AndResGuard mapping for obfuscated APKs.","Re-extract to a clean directory to rule out truncated XML entries."],"tags":["apk-canary","xml-parsing","binary-xml","resource-decoding"],"backgroundTag":"xml-parse-error","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"}