{"record":{"id":"9a6922eeef92e3e1","repo":"theonedev/onedev","slug":"attempt-to-set-a-model-object-on-a-component-witho","errorCode":null,"errorMessage":"Attempt to set a model object on a component without a model! ","messagePattern":"Attempt to set a model object on a component without a model! ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/org/apache/wicket/Component.java","lineNumber":3130,"sourceCode":"\t * Sets the backing model object. Unlike <code>getDefaultModel().setObject(object)</code>, this\n\t * method checks authorisation and model comparator, and invokes <code>modelChanging</code> and\n\t * <code>modelChanged</code> if the value really changes.\n\t * \n\t * @param object\n\t *            The object to set\n\t * @return This\n\t * @throws IllegalStateException If the component has neither its own model nor any of its\n\t * parents uses {@link IComponentInheritedModel}\n\t */\n\t@SuppressWarnings(\"unchecked\")\n\tpublic final Component setDefaultModelObject(final Object object)\n\t{\n\t\tfinal IModel<Object> model = (IModel<Object>)getDefaultModel();\n\n\t\t// Check whether anything can be set at all\n\t\tif (model == null)\n\t\t{\n\t\t\tthrow new IllegalStateException(\n\t\t\t\t\"Attempt to set a model object on a component without a model! \" +\n\t\t\t\t\"Either pass an IModel to the constructor or use #setDefaultModel(new SomeModel(object)). \" +\n\t\t\t\t\"Component: \" + getPageRelativePath());\n\t\t}\n\n\t\t// Check authorization\n\t\tif (!isActionAuthorized(ENABLE))\n\t\t{\n\t\t\tthrow new UnauthorizedActionException(this, ENABLE);\n\t\t}\n\n\t\t// Check whether this will result in an actual change\n\t\tif (!getModelComparator().compare(this, object))\n\t\t{\n\t\t\tmodelChanging();\n\t\t\tmodel.setObject(object);\n\t\t\tmodelChanged();\n\t\t}","sourceCodeStart":3112,"sourceCodeEnd":3148,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/apache/wicket/Component.java#L3112-L3148","documentation":"Wicket's setModelObject() (and model-changing setters) require the component to have an IModel assigned. When getDefaultModel() returns null there is nothing to set the object into, so Wicket throws IllegalStateException and points you at the component's page-relative path. The library does this because a plain component constructed without a model has no backing storage for the object.","triggerScenarios":"Calling component.setModelObject(obj) or setObject() on a model when the component was constructed with only a String id, e.g. new Label(\"myLabel\") with no IModel, then attempting to set its value.","commonSituations":"Constructing components with just an id during quick prototyping; moving code around so the model assignment was dropped; calling setModelObject from an event handler (link onClick, form onSubmit) on a component created elsewhere without a model.","solutions":["Pass an IModel to the component constructor: new Label(\"id\", model) or new Label(\"id\", someObject).","Call component.setDefaultModel(new Model/myModel(object)) before setModelObject is invoked.","If the component should be static, remove the setModelObject call instead of adding a model."],"exampleFix":"// before\nLabel label = new Label(\"name\");\nlabel.setModelObject(\"Alice\");\n// after\nLabel label = new Label(\"name\", Model.of(\"Alice\"));\nlabel.setModelObject(\"Alice\"); // now legal","handlingStrategy":"validation","validationCode":"if (component.getDefaultModel() == null) {\n    component.setDefaultModel(Model.of(\"\")); // or pass model in constructor\n}\ncomponent.setModelObject(value);","typeGuard":"if (!(component instanceof Page) && component.getDefaultModel() == null) { /* supply model first */ }","tryCatchPattern":"try { component.setModelObject(value); } catch (IllegalStateException e) { component.setDefaultModel(Model.of(value)); }","preventionTips":["Always pass an IModel in the component constructor when the value will be updated.","Favor PropertyModel/Model.of over setModelObject on bare components.","Review constructors that drop the model argument during refactors."],"tags":["wicket","model","illegal-state","component"],"backgroundTag":"missing-required-argument","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}