JetBrains/intellij-community · error · CodeGenerationException

Recursive form nesting is not allowed

Error message

Recursive form nesting is not allowed

What it means

During nested-form compilation, Utils.validateNestedFormLoop throws RecursiveFormNestingException when the nested-form graph contains a cycle (form A embeds B which embeds A, directly or transitively); AsmCodeGenerator converts it to CodeGenerationException('Recursive form nesting is not allowed') because expanding such a graph would recurse infinitely.

Source

Thrown at java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java:416

        }
        try {
          nestedFormContainer = myFormLoader.loadForm(nestedForm.getFormFileName());
        }
        catch (Exception e) {
          throw new CodeGenerationException(lwComponent.getId(), e.getMessage());
        }
        // if nested form is empty, ignore
        if (nestedFormContainer.getComponentCount() == 0) {
          return;
        }
        if (nestedFormContainer.getComponent(0).getBinding() == null) {
          throw new CodeGenerationException(lwComponent.getId(), "No binding on root component of nested form " + nestedForm.getFormFileName());
        }
        try {
          Utils.validateNestedFormLoop(nestedForm.getFormFileName(), myFormLoader);
        }
        catch (RecursiveFormNestingException e) {
          throw new CodeGenerationException(lwComponent.getId(), "Recursive form nesting is not allowed");
        }
        className = myFormLoader.getClassToBindName(nestedFormContainer);
      }
      else {
        className = getComponentCodeGenerator(lwComponent.getParent()).mapComponentClass(lwComponent.getComponentClassName());
      }
      Type componentType = typeFromClassName(className);
      int componentLocal = generator.newLocal(componentType);

      myIdToLocalMap.put(lwComponent.getId(), Integer.valueOf(componentLocal));

      InstrumentationClassFinder.PseudoClass componentClass = getComponentClass(className, myFinder);
      validateFieldBinding(lwComponent, componentClass);

      if (myIgnoreCustomCreation) {
        try {
          boolean creatable = true;
          if ((componentClass.getModifiers() & (Modifier.PRIVATE | Modifier.ABSTRACT)) != 0) {

View on GitHub (pinned to be881553f2)

Solutions

  1. Break the cycle: identify it from the exception/chain (A->B->A) and remove or restructure one include so the graph is a DAG
  2. Extract the mutually-shared part into a third form included by both, instead of including each other
  3. If nesting looks accidental, check the nested-form component's formFileName in the designer and repoint it
Defensive patterns

Strategy: validation

Validate before calling

try {
  Utils.validateNestedFormLoop(formFileName, formLoader);
} catch (RecursiveFormNestingException e) {
  // report the cycle and which include to remove, before compilation
}

Try / catch

catch (CodeGenerationException e) if 'Recursive form nesting is not allowed': trace the include chain, remove one include to break the cycle

Prevention

When it happens

Trigger: Compiling a form whose nested-form include chain loops back on itself: A includes B, B includes A; or longer cycles A->B->C->A.

Common situations: Copy-pasting forms and re-pointing nested-form references at each other; refactoring a shared panel into a form and accidentally including the container form inside it; hand-editing form XML include paths.

Related errors


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