jenkinsci/jenkins · error · IllegalStateException

{view.getViewName()} view can not contain views

Error message

{view.getViewName()} view can not contain views

What it means

IllegalStateException from ViewOptionHandler when the path still has tokens but the current view is not a ViewGroup (it cannot contain child views). The check is `else if (tok.hasMoreTokens())` after the `view instanceof ViewGroup` branch.

Source

Thrown at core/src/main/java/hudson/cli/handlers/ViewOptionHandler.java:114

        final StringTokenizer tok = new StringTokenizer(name, "/");
        while (tok.hasMoreTokens()) {

            String viewName = tok.nextToken();

            view = group.getView(viewName);
            if (view == null) {
                group.checkPermission(View.READ);
                throw new IllegalArgumentException(String.format(
                        "No view named %s inside view %s",
                        viewName, group.getDisplayName()
                ));
            }
            view.checkPermission(View.READ);
            if (view instanceof ViewGroup) {
                group = (ViewGroup) view;
            } else if (tok.hasMoreTokens()) {
                throw new IllegalStateException(view.getViewName() + " view can not contain views");
            }
        }

        return view;
    }

    @Override
    public String getDefaultMetaVariable() {

        return "VIEW";
    }
}

View on GitHub (pinned to 2e228ff40b)

Solutions

  1. Pass only the leaf view's own name (drop the extra path segments).
  2. Confirm the parent segment is actually a ViewGroup before nesting.
  3. Use a view type that implements ViewGroup if nesting is required.
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(view instanceof ViewGroup) && tok.hasMoreTokens()) {
    throw new IllegalStateException(view.getViewName() + " cannot contain views");
}

Type guard

boolean canNest(View v) { return v instanceof ViewGroup; }

Try / catch

catch (IllegalStateException e) { /* leaf view used as a path parent */ }

Prevention

When it happens

Trigger: A view path like `-v a/b/c` where `a` (or `a/b`) resolves to a leaf view that does not implement ViewGroup.

Common situations: Treating a flat/leaf view as if it were nested; plugin view type that aggregates but is not a ViewGroup.

Related errors


AI-assisted analysis of jenkinsci/jenkins@2e228ff40b (2026-08-14). Data as JSON: /api/errors/9884684ebf068287. Report an issue: GitHub.