{"record":{"id":"77ff95d78cb0eb82","repo":"theonedev/onedev","slug":"the-component-id-must-not-contain-or-chars","errorCode":null,"errorMessage":"The component ID must not contain ':' or '~' chars.","messagePattern":"The component ID must not contain ':' or '~' chars\\.","errorType":"exception","errorClass":"org.apache.wicket.WicketRuntimeException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/org/apache/wicket/Component.java","lineNumber":4389,"sourceCode":"\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\n\t * the parent will not know the child. This might not be a problem in some cases, but e.g.\n\t * child.onDetach() will not be invoked (since the parent doesn't know it is his child).\n\t * \n\t * @param parent\n\t *            The parent container\n\t */","sourceCodeStart":4371,"sourceCodeEnd":4407,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/apache/wicket/Component.java#L4371-L4407","documentation":"setId() also rejects ids containing ':' or '~' because those characters have special meaning in Wicket component paths (':' separates path segments, '~' is used in AJAX/versioned paths) and would break path resolution.","triggerScenarios":"Constructing a component with an id like \"form:field\", \"a~b\", or an id built by concatenating user/data values that contain these characters.","commonSituations":"Developers trying to encode hierarchy directly into an id (paths are computed by Wicket itself); ids taken from external identifiers containing colons (URIs, timestamps like 12:30); localization keys pasted as component ids.","solutions":["Sanitize the id: strip/replace ':' and '~' characters before constructing the component.","Use a safe derived key (e.g. hash or index) instead of raw external identifiers as ids.","Do not encode hierarchy in ids; nest components in containers so Wicket builds the path."],"exampleFix":"// before\nLabel l = new Label(\"row:\" + index, model);\n// after\nString safeId = \"row-\" + index; // no ':' or '~'\nLabel l = new Label(safeId, model);","handlingStrategy":"validation","validationCode":"if (id.indexOf(':') != -1 || id.indexOf('~') != -1) { id = id.replaceAll(\"[:~]\", \"-\"); }","typeGuard":"boolean safeId = id != null && id.matches(\"[A-Za-z0-9_-]+\");","tryCatchPattern":"try { new Label(id, model); } catch (WicketRuntimeException e) { new Label(id.replaceAll(\"[:~]\", \"_\"), model); }","preventionTips":["Sanitize external identifiers before using them as component ids.","Never encode hierarchy in ids; use nested containers instead.","Restrict ids to letters, digits, '-' and '_' by convention."],"tags":["wicket","component-id","validation","identifier"],"backgroundTag":"invalid-identifier-format","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"}