apache/hadoop · error · IOException

Got unexpected attribute: {ev}

Error message

Got unexpected attribute: {ev}

What it means

expectTag scans for the next start/end element and throws on any XMLEvent.ATTRIBUTE. The XML produced by oiv's XML processor uses plain nested elements with text values and never attributes, so an attribute proves the input was rewritten by another tool (or hand-authored against a different schema) and cannot be mapped onto the fsimage schema by this reconstructor.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/tools/offlineImageViewer/OfflineImageReconstructor.java:199

   *                     unless this string is enclosed in braces.
   * @param allowEnd     If true, we will also end events.
   *                     If false, end events cause an exception.
   *
   * @return             The next tag start or end event.
   */
  private XMLEvent expectTag(String expected, boolean allowEnd)
      throws IOException {
    XMLEvent ev = null;
    while (true) {
      try {
        ev = events.nextEvent();
      } catch (XMLStreamException e) {
        throw new IOException("Expecting " + expected +
            ", but got XMLStreamException", e);
      }
      switch (ev.getEventType()) {
      case XMLEvent.ATTRIBUTE:
        throw new IOException("Got unexpected attribute: " + ev);
      case XMLEvent.CHARACTERS:
        if (!ev.asCharacters().isWhiteSpace()) {
          throw new IOException("Got unxpected characters while " +
              "looking for " + expected + ": " +
              ev.asCharacters().getData());
        }
        break;
      case XMLEvent.END_ELEMENT:
        if (!allowEnd) {
          throw new IOException("Got unexpected end event " +
              "while looking for " + expected);
        }
        return ev;
      case XMLEvent.START_ELEMENT:
        if (!expected.startsWith("[")) {
          if (!ev.asStartElement().getName().getLocalPart().
                equals(expected)) {
            throw new IOException("Failed to find <" + expected + ">; " +

View on GitHub (pinned to 2add963021)

Solutions

  1. Convert every attribute back to a child element with the attribute's name and its value as text
  2. Regenerate the XML directly with `hdfs oiv -p XML -i <fsimage> -o img.xml` and redo the edit structurally
  3. If a transform step is unavoidable, assert its output is attribute-free: xmllint --xpath '//*[attribute::*]' img.xml must return nothing

Example fix

<!-- before -->
<inode id="16386" type="FILE"></inode>

<!-- after -->
<inode><id>16386</id><type>FILE</type></inode>
Defensive patterns

Strategy: validation

Validate before calling

# oiv XML must contain zero attributes
n=$(xmllint --xpath 'count(//*[attribute::*])' fsimage.xml 2>/dev/null)
[ "$n" = "0" ] || { echo "$n attribute(s) present - convert them to child elements"; exit 1; }

Prevention

When it happens

Trigger: ReverseXML on XML that a pretty-printer, XSLT step, or data tool rewrote by hoisting child text into attributes (e.g. <inode id="16386"> instead of <inode><id>16386</id>), or hand-authored files modeled on another Hadoop tool's dialect.

Common situations: ETL/XSLT pipelines between the XML dump and reconstruction; editors that 'normalize' markup; examples copied from tools that legitimately use attributes.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/48dc742864ffa2a6. Report an issue: GitHub.