{"record":{"id":"a39525bb025d05c5","repo":"jenkinsci/jenkins","slug":"view-can-not-be-modified-directly","errorCode":null,"errorMessage":"'{}' view can not be modified directly","messagePattern":"'(.+?)' view can not be modified directly","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"warning","filePath":"core/src/main/java/hudson/cli/AddJobToViewCommand.java","lineNumber":57,"sourceCode":"public class AddJobToViewCommand extends CLICommand {\n\n    @Argument(usage = \"Name of the view\", required = true, index = 0)\n    private View view;\n\n    @SuppressWarnings(\"MismatchedQueryAndUpdateOfCollection\")\n    @Argument(usage = \"Job names\", required = true, index = 1)\n    private List<TopLevelItem> jobs;\n\n    @Override\n    public String getShortDescription() {\n        return Messages.AddJobToViewCommand_ShortDescription();\n    }\n\n    @Override\n    protected int run() throws Exception {\n        view.checkPermission(View.CONFIGURE);\n\n        if (!(view instanceof DirectlyModifiableView)) throw new IllegalStateException(\n                \"'\" + view.getDisplayName() + \"' view can not be modified directly\");\n\n        for (TopLevelItem job : jobs) {\n            ((DirectlyModifiableView) view).add(job);\n        }\n\n        return 0;\n    }\n}\n","sourceCodeStart":39,"sourceCodeEnd":67,"githubUrl":"https://github.com/jenkinsci/jenkins/blob/2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc/core/src/main/java/hudson/cli/AddJobToViewCommand.java#L39-L67","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"// Check view type before calling add\nif (view instanceof DirectlyModifiableView) {\n    ((DirectlyModifiableView) view).add(job);\n} else {\n    throw new AbortException(\"View '\" + view.getDisplayName() + \"' does not support direct job modification. Use a List View.\");\n}","typeGuard":"public static boolean isDirectlyModifiable(View view) {\n    return view instanceof DirectlyModifiableView;\n}","tryCatchPattern":"try {\n    // add-job-to-view logic\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"can not be modified directly\")) {\n        stderr.println(e.getMessage());\n        stderr.println(\"Use a List View or other DirectlyModifiableView type.\");\n        return 1;\n    }\n    throw e;\n}","preventionTips":["Check instanceof DirectlyModifiableView before performing add/remove operations.","Document which view types support direct modification.","Avoid scripting against the 'All' view."],"tags":["cli","view","configuration","type-check"],"backgroundTag":null,"analyzedSha":"2e228ff40b14dbc8b14ffbc6edf0e4383cf744fc","analyzedAt":"2026-08-14T07:07:15.274Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}