JetBrains/intellij-community · error · UnexpectedFormElementException

unexpected element: {element}

Error message

unexpected element: {element}

What it means

Thrown by LwRootContainer.read when the root element of a parsed form file has the right namespace (Utils.FORM_NAMESPACE) but is not named 'form'. The lightweight reader only accepts <form> as the document root; anything else with the designer namespace is a structural error and raises UnexpectedFormElementException with the offending element.

Source

Thrown at java/compiler/forms-compiler/src/com/intellij/uiDesigner/lw/LwRootContainer.java:47

  @Override
  public String getClassToBind(){
    return myClassToBind;
  }

  public void setClassToBind(final String classToBind) {
    myClassToBind = classToBind;
  }

  @Override
  public void read(final Element element, final PropertiesProvider provider) throws Exception {
    if (element == null) {
      throw new IllegalArgumentException("element cannot be null");
    }
    if (!Utils.FORM_NAMESPACE.equals(element.getNamespace().getURI())) {
      throw new AlienFormFileException();
    }
    if(!"form".equals(element.getName())){
      throw new UnexpectedFormElementException("unexpected element: "+element);
    }

    setId("root");

    myClassToBind = element.getAttributeValue(UIFormXmlConstants.ATTRIBUTE_BIND_TO_CLASS);

    // Constraints and properties
    for (final Element child : element.getChildren()) {
      if (child.getName().equals(UIFormXmlConstants.ELEMENT_BUTTON_GROUPS)) {
        readButtonGroups(child);
      }
      else if (child.getName().equals(UIFormXmlConstants.ELEMENT_INSPECTION_SUPPRESSIONS)) {
        readInspectionSuppressions(child);
      }
      else {
        final LwComponent component = createComponentFromTag(child);
        addComponent(component);
        component.read(child, provider);

View on GitHub (pinned to be881553f2)

Solutions

  1. Rename the root element of the file to exactly <form xmlns="http://www.intellij.com/ui/forms">.
  2. Verify the code is loading the intended .form file path.
  3. Let the GUI designer create/save the file so the root structure is canonical.

Example fix

<!-- before -->
<forms xmlns="http://www.intellij.com/ui/forms"> ... </forms>

<!-- after -->
<form xmlns="http://www.intellij.com/ui/forms"> ... </form>
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check the document root before handing it to the reader
if (!"form".equals(rootElement.getName()) || !Utils.FORM_NAMESPACE.equals(rootElement.getNamespace().getURI())) {
  throw new IllegalArgumentException("Not a GUI Designer form file: " + fileName);
}

Try / catch

try { rootContainer.read(element, provider); } catch (UnexpectedFormElementException | AlienFormFileException e) { /* wrong root element or namespace: verify file path and root tag */ }

Prevention

When it happens

Trigger: Parsing an XML document whose root is, say, <forms> or <Form> (wrong case) while declaring the form namespace, so the namespace check passes but the name check fails. Also triggered when a non-form designer file (other tool's format borrowing the namespace) is fed to Utils.loadFormXml.

Common situations: Hand-created XML files with the designer namespace but a wrong root tag; accidental case mismatch 'Form' vs 'form'; pointing form-loading code at the wrong XML file (one that happens to use the same namespace).

Related errors


AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14). Data as JSON: /api/errors/c4ec501411173d96. Report an issue: GitHub.