apache/hadoop · error · IOException

Unexpected XML event {ev}

Error message

Unexpected XML event {ev}

What it means

loadNodeChildrenHelper builds the in-memory Node tree for a subtree and handles only START_ELEMENT, CHARACTERS, and ignorable event types; an ATTRIBUTE event throws this IOException. It is the subtree-loading twin of the attribute check in expectTag: oiv XML never uses attributes, so any attribute inside a section subtree marks input produced or rewritten by something other than the oiv XML processor.

Source

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

          String key = ev.asStartElement().getName().getLocalPart();
          for (String terminator : terminators) {
            if (terminator.equals(key)) {
              return;
            }
          }
          events.nextEvent();
          Node node = new Node();
          parent.addChild(key, node);
          loadNodeChildrenHelper(node, expected, new String[0]);
          break;
        case XMLEvent.CHARACTERS:
          String val = XMLUtils.
              unmangleXmlString(ev.asCharacters().getData(), false);
          parent.setVal(parent.getVal() + val);
          events.nextEvent();
          break;
        case XMLEvent.ATTRIBUTE:
          throw new IOException("Unexpected XML event " + ev);
        default:
          // Ignore other event types like comment, etc.
          if (LOG.isTraceEnabled()) {
            LOG.trace("Skipping XMLEvent " + ev);
          }
          events.nextEvent();
          break;
        }
      } catch (XMLStreamException e) {
        throw new IOException("Expecting " + expected +
            ", but got XMLStreamException", e);
      }
    }
  }

  /**
   * Load a subtree of the XML into a Node structure.
   * We will keep consuming XML events until we exit the current subtree.

View on GitHub (pinned to 2add963021)

Solutions

  1. Convert all attributes to child elements holding the value as text
  2. Regenerate the XML with `hdfs oiv -p XML` from the source fsimage
  3. Gate the pipeline: xmllint --xpath 'count(//*[attribute::*])' img.xml must return 0

Example fix

<!-- before -->
<inode type="FILE"><name>part-00000</name></inode>

<!-- after -->
<inode><type>FILE</type><name>part-00000</name></inode>
Defensive patterns

Strategy: validation

Validate before calling

n=$(xmllint --xpath 'count(//*[attribute::*])' fsimage.xml 2>/dev/null)
[ "$n" = "0" ] || { echo "$n attribute(s) present - oiv schema uses child elements only"; exit 1; }

Prevention

When it happens

Trigger: ReverseXML on XML whose elements carry attributes anywhere within a section subtree - e.g. <inode type="FILE"> - after a pretty-printer, custom exporter, or hand authoring introduced them.

Common situations: Transform pipelines (XSLT, JSON-to-XML converters) between dump and reconstruction; hand-authored entries modeled on attribute-style schemas.

Related errors


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