jenkinsci/jenkins · warning · IllegalStateException
'{}' view can not be modified directly
Error message
'{}' view can not be modified directly What it means
Thrown by AddJobToViewCommand.run() when the resolved view is not an instance of DirectlyModifiableView. Only views implementing DirectlyModifiableView (e.g., ListView) support programmatic add/remove of jobs. The message includes the view's display name.
Source
Thrown at core/src/main/java/hudson/cli/AddJobToViewCommand.java:57
public class AddJobToViewCommand extends CLICommand {
@Argument(usage = "Name of the view", required = true, index = 0)
private View view;
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
@Argument(usage = "Job names", required = true, index = 1)
private List<TopLevelItem> jobs;
@Override
public String getShortDescription() {
return Messages.AddJobToViewCommand_ShortDescription();
}
@Override
protected int run() throws Exception {
view.checkPermission(View.CONFIGURE);
if (!(view instanceof DirectlyModifiableView)) throw new IllegalStateException(
"'" + view.getDisplayName() + "' view can not be modified directly");
for (TopLevelItem job : jobs) {
((DirectlyModifiableView) view).add(job);
}
return 0;
}
}
View on GitHub (pinned to 2e228ff40b)
Solutions
- Use a view type that implements DirectlyModifiableView — typically 'List View' (ListView).
- If a custom view plugin is involved, check its documentation for DirectlyModifiableView support or use its own API for job management.
- Avoid targeting the 'All' view — it is read-only and auto-includes all jobs.
Defensive patterns
Strategy: type-guard
Validate before calling
// Check view type before calling add
if (view instanceof DirectlyModifiableView) {
((DirectlyModifiableView) view).add(job);
} else {
throw new AbortException("View '" + view.getDisplayName() + "' does not support direct job modification. Use a List View.");
} Type guard
public static boolean isDirectlyModifiable(View view) {
return view instanceof DirectlyModifiableView;
} Try / catch
try {
// add-job-to-view logic
} catch (IllegalStateException e) {
if (e.getMessage().contains("can not be modified directly")) {
stderr.println(e.getMessage());
stderr.println("Use a List View or other DirectlyModifiableView type.");
return 1;
}
throw e;
} Prevention
- Check instanceof DirectlyModifiableView before performing add/remove operations.
- Document which view types support direct modification.
- Avoid scripting against the 'All' view.
When it happens
Trigger: The CLI 'add-job-to-view' or 'remove-job-from-view' command resolves the target view, checks view instanceof DirectlyModifiableView, and throws if it doesn't implement the interface.
Common situations: Targeting the 'All' view (AllView does not implement DirectlyModifiableView — it is a computed/aggregate view); targeting a custom view plugin that doesn't implement DirectlyModifiableView; using a view type that only supports drag-and-drop or configuration-based job membership.
Related errors
- '{view.getDisplayName()}' view can not be modified directly
- Could not get TcpSlaveAgentListener host name
- {} is not parameterized but the -p option was specified.
- {} has no SCM trigger, but checkSCM was specified
- Cannot build {0} for unknown reasons.
AI-assisted analysis of jenkinsci/jenkins@2e228ff40b (2026-08-14).
Data as JSON: /api/errors/a39525bb025d05c5.
Report an issue: GitHub.