{"record":{"id":"91dab52bc0c7481b","repo":"theonedev/onedev","slug":"null-or-empty-component-id-s-are-not-allowed","errorCode":null,"errorMessage":"Null or empty component ID's are not allowed.","messagePattern":"Null or empty component ID's are not allowed\\.","errorType":"exception","errorClass":"org.apache.wicket.WicketRuntimeException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/org/apache/wicket/Component.java","lineNumber":4383,"sourceCode":"\t\t\t\t// thus will not throw an exception.\n\t\t\t\tmarkupStream.throwMarkupException(\"Expected close tag for \" + openTag);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Sets the id of this component.\n\t * \n\t * @param id\n\t *            The non-null id of this component\n\t */\n\tfinal Component setId(final String id)\n\t{\n\t\tif (!(this instanceof Page))\n\t\t{\n\t\t\tif (Strings.isEmpty(id))\n\t\t\t{\n\t\t\t\tthrow new WicketRuntimeException(\"Null or empty component ID's are not allowed.\");\n\t\t\t}\n\t\t}\n\n\t\tif ((id != null) && (id.indexOf(':') != -1 || id.indexOf('~') != -1))\n\t\t{\n\t\t\tthrow new WicketRuntimeException(\"The component ID must not contain ':' or '~' chars.\");\n\t\t}\n\n\t\tthis.id = id;\n\t\treturn this;\n\t}\n\n\t/**\n\t * THIS IS A WICKET INTERNAL API. DO NOT USE IT.\n\t * \n\t * Sets the parent of a component. Typically what you really want is parent.add(child).\n\t * <p/>\n\t * Note that calling setParent() and not parent.add() will connect the child to the parent, but","sourceCodeStart":4365,"sourceCodeEnd":4401,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/apache/wicket/Component.java#L4365-L4401","documentation":"Component.setId() (package-private, invoked by constructors) throws WicketRuntimeException when the component id is null or the empty string, except for Page components. Every component needs a non-empty id because it is matched against the wicket:id in markup and used in path construction.","triggerScenarios":"new Label(null, ...) or new Label(\"\", ...); passing a variable holding null/empty as the component id; building ids dynamically from data that is blank.","commonSituations":"Ids derived from database values or i18n keys that come back empty; typos where the id argument was accidentally omitted; reflection-driven component factories feeding empty ids.","solutions":["Pass a literal non-empty id: new Label(\"myId\", model).","Validate/derive the id before constructing the component and fail early with a clear message.","If the id is dynamic, ensure a fallback non-empty value is used."],"exampleFix":"// before\nString id = config.getId(); // may be \"\"\nLabel label = new Label(id, \"v\");\n// after\nString id = config.getId();\nif (id == null || id.isEmpty()) { throw new IllegalArgumentException(\"missing component id\"); }\nLabel label = new Label(id, \"v\");","handlingStrategy":"validation","validationCode":"if (id == null || id.isEmpty()) throw new IllegalArgumentException(\"component id required\");","typeGuard":"boolean validId = id != null && !id.trim().isEmpty();","tryCatchPattern":"try { new Label(id, model); } catch (WicketRuntimeException e) { throw new IllegalArgumentException(\"blank component id: \" + e.getMessage()); }","preventionTips":["Use string literals for component ids wherever possible.","Validate dynamically derived ids before constructing components.","Fail fast in factories that build components from data."],"tags":["wicket","component-id","validation","null"],"backgroundTag":"empty-required-field","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}