MuntashirAkon/AppManager · error · org.xmlpull.v1.XmlPullParserException

${e}

Error message

${e}

What it means

During setInput, reading the magic header or consuming the optional START_DOCUMENT token can raise an IOException (bad magic, short stream, corrupted data). setInput translates any such IOException into an XmlPullParserException whose message is the exception's toString(), so parsers following the XmlPullParser contract get the right exception type.

Solutions

  1. Catch XmlPullParserException and inspect its message/cause to identify the underlying IOException.
  2. Verify the stream is open, positioned at the start, and contains a complete binary XML document.
  3. Log the embedded exception (e.getMessage()) — it is the original IOException's toString().

Example fix

// before
parser.setInput(is, null); // throws XmlPullParserException("java.io.EOFException") with no context
// after
try {
    parser.setInput(is, null);
} catch (XmlPullParserException e) {
    Log.e(TAG, "Failed to read binary XML header", e);
}
Defensive patterns

Strategy: try-catch

Validate before calling

File f = new File(path);
if (!f.isFile() || f.length() < 4) throw new IOException("Not a binary XML file: " + path);

Try / catch

try {
    parser.setInput(is, null);
} catch (XmlPullParserException e) {
    // e's message is the wrapped IOException's toString(); log and recover
    Log.e(TAG, "Binary XML header read failed", e);
}

Prevention

When it happens

Trigger: setInput(InputStream, String) when the underlying stream throws IOException while reading the 4-byte magic or the first token: empty stream, truncated file, closed/broken stream, or unexpected magic.

Common situations: Passing an already-consumed or closed stream; feeding a zero-byte or truncated binary XML file; network/socket streams cut off mid-header; wrong file handed to the parser.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of MuntashirAkon/AppManager@0152f468fc (2026-09-12). Data as JSON: /api/errors/da250d935565c156. Report an issue: GitHub.

Appendix: source

Thrown at libcore/compat/src/main/java/io/github/muntashirakon/compat/xml/BinaryXmlPullParser.java:115

        mAttributes = new Attribute[8];
        for (int i = 0; i < mAttributes.length; i++) {
            mAttributes[i] = new Attribute();
        }

        try {
            final byte[] magic = new byte[4];
            mIn.readFully(magic);
            if (!Arrays.equals(magic, PROTOCOL_MAGIC_VERSION_0)) {
                throw new IOException("Unexpected magic " + bytesToHexString(magic));
            }

            // We're willing to immediately consume a START_DOCUMENT if present,
            // but we're okay if it's missing
            if (peekNextExternalToken() == START_DOCUMENT) {
                consumeToken();
            }
        } catch (IOException e) {
            throw new XmlPullParserException(e.toString());
        }
    }

    @Override
    public void setInput(Reader in) throws XmlPullParserException {
        throw new UnsupportedOperationException();
    }

    @Override
    public int next() throws XmlPullParserException, IOException {
        while (true) {
            final int token = nextToken();
            switch (token) {
                case START_TAG:
                case END_TAG:
                case END_DOCUMENT:
                    return token;
                case TEXT:

View on GitHub (pinned to 0152f468fc)