MuntashirAkon/AppManager · error · XmlPullParserException

Missing attribute " + name

Error message

Missing attribute " + name

What it means

TypedXmlPullParser.getAttributeIndexOrThrow() is a default interface method that looks up an attribute by name and throws XmlPullParserException("Missing attribute ...") when getAttributeIndex returns -1, i.e. the attribute does not exist on the current tag.

Solutions

  1. Verify the attribute name against the writer's schema; fix typos.
  2. Use getAttributeIndex(ns, name) and handle -1 with a default instead of the OrThrow variant.
  3. Bump/handle document versioning so required attributes are guaranteed present for the version being parsed.
  4. Catch XmlPullParserException around the call and fall back to defaults.

Example fix

// before
int v = parser.getAttributeInt(null, "priority"); // throws if absent
// after
int idx = parser.getAttributeIndex(null, "priority");
int v = idx != -1 ? parser.getAttributeInt(idx) : 0;
Defensive patterns

Strategy: validation

Validate before calling

int idx = parser.getAttributeIndex(namespace, name);
boolean present = idx != -1;

Try / catch

try {
    int v = parser.getAttributeInt(null, "priority");
} catch (XmlPullParserException e) {
    int v = DEFAULT_PRIORITY; // attribute absent
}

Prevention

When it happens

Trigger: Calling getAttributeIndexOrThrow(ns, name) — directly or via getAttributeInt/Long/BytesHex/BytesBase64/IntHex/LongHex wrappers — when the current start tag has no attribute with that name.

Common situations: Parser version skew (writer omitted an optional attribute), reading documents produced by older app versions, or a typo in the attribute name.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at libcore/compat/src/main/java/io/github/muntashirakon/compat/xml/TypedXmlPullParser.java:39

        final int count = getAttributeCount();
        for (int i = 0; i < count; i++) {
            if ((namespaceNull || namespace.equals(getAttributeNamespace(i)))
                    && name.equals(getAttributeName(i))) {
                return i;
            }
        }
        return -1;
    }

    /**
     * @return index of requested attribute
     * @throws XmlPullParserException if the value is undefined
     */
    default int getAttributeIndexOrThrow(@Nullable String namespace, @NonNull String name)
            throws XmlPullParserException {
        final int index = getAttributeIndex(namespace, name);
        if (index == -1) {
            throw new XmlPullParserException("Missing attribute " + name);
        } else {
            return index;
        }
    }

    /**
     * @return decoded strongly-typed {@link #getAttributeValue}
     * @throws XmlPullParserException if the value is malformed
     */
    @NonNull
    byte[] getAttributeBytesHex(int index) throws XmlPullParserException;

    /**
     * @return decoded strongly-typed {@link #getAttributeValue}
     * @throws XmlPullParserException if the value is malformed
     */
    @NonNull
    byte[] getAttributeBytesBase64(int index) throws XmlPullParserException;

View on GitHub (pinned to 0152f468fc)