{"record":{"id":"707b8ae73ca4fe85","repo":"MuntashirAkon/AppManager","slug":"unknown-token-token-with-type-type","errorCode":null,"errorMessage":"Unknown token ${token} with type ${type}","messagePattern":"Unknown token (.+?) with type (.+?)","errorType":"exception","errorClass":"java.io.IOException","httpStatus":null,"severity":"error","filePath":"libcore/compat/src/main/java/io/github/muntashirakon/compat/xml/BinaryXmlPullParser.java","lineNumber":292,"sourceCode":"            case XmlPullParser.TEXT:\n            case XmlPullParser.CDSECT:\n            case XmlPullParser.PROCESSING_INSTRUCTION:\n            case XmlPullParser.COMMENT:\n            case XmlPullParser.DOCDECL:\n            case XmlPullParser.IGNORABLE_WHITESPACE: {\n                mCurrentName = null;\n                mCurrentText = mIn.readUTF();\n                if (mAttributeCount > 0) resetAttributes();\n                break;\n            }\n            case XmlPullParser.ENTITY_REF: {\n                mCurrentName = mIn.readUTF();\n                mCurrentText = resolveEntity(mCurrentName);\n                if (mAttributeCount > 0) resetAttributes();\n                break;\n            }\n            default: {\n                throw new IOException(\"Unknown token \" + token + \" with type \" + type);\n            }\n        }\n    }\n\n    /**\n     * When the current tag is {@link #TEXT}, consume all subsequent \"text\"\n     * events, as described by {@link #next}. When finished, the current event\n     * will still be {@link #TEXT}.\n     */\n    private void consumeAdditionalText() throws IOException, XmlPullParserException {\n        String combinedText = mCurrentText;\n        while (true) {\n            final int token = peekNextExternalToken();\n            switch (token) {\n                case COMMENT:\n                case PROCESSING_INSTRUCTION:\n                    // Quietly consumed\n                    consumeToken();","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/MuntashirAkon/AppManager/blob/0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5/libcore/compat/src/main/java/io/github/muntashirakon/compat/xml/BinaryXmlPullParser.java#L274-L310","documentation":"consumeToken() switches over the XmlPullParser token constants (START_DOCUMENT, START_TAG, TEXT, END_TAG, END_DOCUMENT). A token value outside the protocol's known set means the stream is desynchronized or corrupt, so it throws IOException \"Unknown token <token> with type <type>\".","triggerScenarios":"Reading a token byte that maps to no known token — corrupted file, wrong stream offset, a stream produced by an incompatible writer/version, or byte misalignment after a prior parse failure.","commonSituations":"Continuing to parse after an earlier exception left the stream mid-token; passing non-binary-XML data that slipped past other checks; truncated files where data bytes are interpreted as tokens; protocol version mismatch.","solutions":["Restart parsing from a fresh stream positioned at the document start instead of continuing after a failure.","Verify the file's integrity and that it was produced by a compatible version of the binary XML writer.","Confirm the magic header was consumed exactly once (setInput does this); do not skip or re-read the header manually.","Log the offending token/type values to diagnose the misalignment."],"exampleFix":"// before\nparser.next(); // after an earlier IOException, stream is misaligned\nparser.next(); // Unknown token ...\n// after\nparser = newBinaryXmlPullParser(); // fresh parser\nparser.setInput(freshInputStream, null);","handlingStrategy":"try-catch","validationCode":"// Ensure a clean start for every parse attempt:\nInputStream fresh = new FileInputStream(file);\nbyte[] magic = new byte[4];\nif (fresh.read(magic) != 4 || !Arrays.equals(magic, PROTOCOL_MAGIC_VERSION_0)) {\n    throw new IOException(\"Not binary XML\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    parser.setInput(is, null);\n    // parse\n} catch (IOException e) {\n    // stream is desynchronized or corrupt: re-create parser + stream, do not resume\n}","preventionTips":["Always restart from a fresh parser and stream after any parse exception.","Do not manually skip or re-read the magic header; setInput handles it.","Validate file integrity (regenerate from source) before parsing."],"tags":["xml","binary","token","stream-desync"],"backgroundTag":"unexpected-response-shape","analyzedSha":"0152f468fc9463ee02dc2ca83f6fe4989a2c4ca5","analyzedAt":"2026-09-12T14:03:37.243Z","contentChangedAt":"2026-09-12T14:03:37.243Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}