{"record":{"id":"7e75008b85eff299","repo":"theonedev/onedev","slug":"replacement-component-must-have-the-same-id-as-the","errorCode":null,"errorMessage":"Replacement component must have the same id as the component it will replace. Replacement id [[","messagePattern":"Replacement component must have the same id as the component it will replace\\. Replacement id \\[\\[","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/org/apache/wicket/Component.java","lineNumber":2823,"sourceCode":"\t * \n\t * and provides a better context for errors.\n\t * <p>\n\t * Usage: <code>component = component.replaceWith(replacement);</code>\n\t * </p>\n\t * \n\t * @since 1.2.1\n\t * \n\t * @param replacement\n\t *            component to replace this one\n\t * @return the component which replaced this one\n\t */\n\tpublic Component replaceWith(Component replacement)\n\t{\n\t\tArgs.notNull(replacement, \"replacement\");\n\n\t\tif (!getId().equals(replacement.getId()))\n\t\t{\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\"Replacement component must have the same id as the component it will replace. Replacement id [[\" +\n\t\t\t\t\treplacement.getId() + \"]], replaced id [[\" + getId() + \"]].\");\n\t\t}\n\t\tif (parent == null)\n\t\t{\n\t\t\tthrow new IllegalStateException(\n\t\t\t\t\"This method can only be called on a component that has already been added to its parent.\");\n\t\t}\n\t\tparent.replace(replacement);\n\t\treturn replacement;\n\t}\n\n\t/**\n\t * @param component\n\t *            The component to compare with\n\t * @return True if the given component's model is the same as this component's model.\n\t */\n\tpublic final boolean sameInnermostModel(final Component component)","sourceCodeStart":2805,"sourceCodeEnd":2841,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/apache/wicket/Component.java#L2805-L2841","documentation":"Component.replaceWith() swaps this component for a replacement in the parent, and requires the replacement to have the identical component id (wicket:id). It throws IllegalArgumentException when replacement.getId() differs from this component's id, so that the parent's markup mapping stays consistent.","triggerScenarios":"Creating a replacement component with a different string id than the original (e.g. new Label(\"foo\") replacing new Label(\"bar\")); copying code that renames ids; building replacements dynamically with generated ids.","commonSituations":"Refactoring that renamed one of the two components; constructing replacements in loops with index-based ids; attempting to swap a Panel for a Fragment with a different wicket:id.","solutions":["Ensure the replacement uses exactly the original component's id: `new Label(old.getId(), model)`.","Capture the id from the existing component rather than hardcoding.","If ids must differ, remove the old component and add the new one via the parent instead.","Add a unit/test check comparing getId() before calling replaceWith.","Search markup and Java for mismatched wicket:id strings."],"exampleFix":"// before\nlabel.replaceWith(new MultiLineLabel(\"otherId\", model));\n// after\nlabel.replaceWith(new MultiLineLabel(label.getId(), model));","handlingStrategy":"validation","validationCode":"if (!replacement.getId().equals(existing.getId())) { replacement = rebuildWithId(existing.getId()); }","typeGuard":"boolean swappable(Component old, Component newC) { return old.getId().equals(newC.getId()); }","tryCatchPattern":"try { old.replaceWith(replacement); } catch (IllegalArgumentException e) { log.error(\"Replacement id mismatch: \" + e.getMessage()); }","preventionTips":["Derive the replacement id from the original component, never hardcode","Unit test id-preserving swap helpers","Search both markup and Java when renaming wicket:ids"],"tags":["wicket","component-tree","argument"],"backgroundTag":"invalid-argument-value","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"}