JetBrains/intellij-community · error · UnexpectedFormElementException

unexpected element

Error message

unexpected element: {element}

What it means

Thrown by LwContainer.createComponent (via the createComponent factory in LwContainer) while parsing a form's XML: a child element inside a container matched none of the recognized component element names (component types like tabbed-pane, split-pane, toolbar, and their siblings). UnexpectedFormElementException signals that the .form XML contains an element the lightweight form reader does not know how to turn into an LwComponent.

Solutions

  1. Open the .form file and inspect the element printed in the message; correct the tag name to the expected kebab-case element (e.g. 'tabbed-pane', 'split-pane', 'toolbar').
  2. If the form came from a newer IDE, upgrade the forms-compiler/IDE reading it so the new element names are recognized.
  3. Regenerate the form in the GUI designer instead of hand-editing the XML.
  4. Delete the unrecognized element from the form if the component is not needed.

Example fix

<!-- before -->
<tabbedpane binding="myTabs"> ... </tabbedpane>

<!-- after -->
<tabbed-pane binding="myTabs"> ... </tabbed-pane>
Defensive patterns

Strategy: validation

Validate before calling

// When generating form XML, whitelist container children before writing
Set<String> KNOWN = Set.of("component", "grid", "xy", "tabbed-pane", "split-pane", "toolbar");
if (!KNOWN.contains(childTagName)) throw new IllegalArgumentException("Unknown form element: " + childTagName);

Try / catch

try { Utils.loadFormXml(stream); } catch (UnexpectedFormElementException e) { /* message prints the offending element; fix or remove that tag in the .form file */ }

Prevention

When it happens

Trigger: Parsing a .form file where a container element has a child whose tag is not in the known set — e.g. a typo'd or newer-version tag such as 'tabbedpane' instead of 'tabbed-pane', or an element introduced by a newer IDE format being read by an older forms-compiler. The else branch throws UnexpectedFormElementException with the offending element toString.

Common situations: Form files created by a newer IntelliJ version using new component tags, then opened/compiled by an older forms-compiler; hand-edited form XML with mistyped element names; third-party tools generating non-conforming form XML.

Related errors


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

Appendix: source

Thrown at java/compiler/forms-compiler/src/com/intellij/uiDesigner/lw/LwContainer.java:288

    }
    else if(UIFormXmlConstants.ELEMENT_SCROLLPANE.equals(name)) {
      String className = LwXmlReader.getOptionalString(child, UIFormXmlConstants.ATTRIBUTE_CLASS, "javax.swing.JScrollPane");
      component = new LwScrollPane(className);
    }
    else if(UIFormXmlConstants.ELEMENT_TABBEDPANE.equals(name)){
      String className = LwXmlReader.getOptionalString(child, UIFormXmlConstants.ATTRIBUTE_CLASS, "javax.swing.JTabbedPane");
      component = new LwTabbedPane(className);
    }
    else if(UIFormXmlConstants.ELEMENT_SPLITPANE.equals(name)){
      String className = LwXmlReader.getOptionalString(child, UIFormXmlConstants.ATTRIBUTE_CLASS, "javax.swing.JSplitPane");
      component = new LwSplitPane(className);
    }
    else if (UIFormXmlConstants.ELEMENT_TOOLBAR.equals(name)) {
      String className = LwXmlReader.getOptionalString(child, UIFormXmlConstants.ATTRIBUTE_CLASS, "javax.swing.JToolBar");
      component = new LwToolBar(className);
    }
    else{
      throw new UnexpectedFormElementException("unexpected element: "+child);
    }
    return component;
  }

  /**
   * 'xy' or 'grid'
   */
  protected final void readLayout(final Element element){
    myLayoutManager = element.getAttributeValue("layout-manager");
    if("xy".equals(element.getName())){
      myLayoutSerializer = XYLayoutSerializer.INSTANCE;
    }
    else if("grid".equals(element.getName())){
      createLayoutSerializer();
    }
    else{
      throw new UnexpectedFormElementException("unexpected element: "+element);
    }

View on GitHub (pinned to be881553f2)