{"record":{"id":"95d1fabc295ee635","repo":"theonedev/onedev","slug":"cannot-remove","errorCode":null,"errorMessage":"Cannot remove ","messagePattern":"Cannot remove ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/org/apache/wicket/Component.java","lineNumber":2321,"sourceCode":"\t */\n\tpublic final void redirectToInterceptPage(final Page page)\n\t{\n\t\tthrow new RestartResponseAtInterceptPageException(page);\n\t}\n\n\t/**\n\t * Removes this component from its parent. It's important to remember that a component that is\n\t * removed cannot be referenced from the markup still.\n\t * <p>\n\t * You must not use this method in your callback to any of the\n\t * {@link MarkupContainer#visitChildren(IVisitor)} methods. See <a\n\t * href=\"https://issues.apache.org/jira/browse/WICKET-3229\">WICKET-3329</a>.\n\t */\n\tpublic final void remove()\n\t{\n\t\tif (parent == null)\n\t\t{\n\t\t\tthrow new IllegalStateException(\"Cannot remove \" + this + \" from null parent!\");\n\t\t}\n\t\tparent.remove(this);\n\t}\n\n\n\t/**\n\t * Render the Component.\n\t */\n\tpublic final void render()\n\t{\n\t\tHierarchicalContext.push(new HierarchicalContext(new ComponentHierarchical(this)));\n\t\ttry {\n\t\t\tRuntimeException exception = null;\n\t\n\t\t\ttry\n\t\t\t{\n\t\t\t\t// Invoke prepareForRender only if this is the root component to be rendered\n\t\t\t\tMarkupContainer parent = getParent();","sourceCodeStart":2303,"sourceCodeEnd":2339,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/apache/wicket/Component.java#L2303-L2339","documentation":"Component.remove() removes the component from its parent, and throws IllegalStateException when the component has no parent (parent == null). Wicket cannot detach a component that was never added to a parent container or was already removed. The message includes the component's toString() to identify the orphan.","triggerScenarios":"Calling component.remove() on a component that was never added via container.add(component), or on one that was already removed (e.g. double remove, remove inside a loop that also removes via parent), or on a root Page-level component detached during serialization.","commonSituations":"Calling remove() in onDetach/onAfterRender when the component was conditionally not added; removing a component twice from event handlers; calling remove() on components obtained from an iterator while the parent removes them.","solutions":["Guard with `if (component.getParent() != null) component.remove();`.","Track whether you added the component yourself before removing it.","Use `component.getParent().remove(component)` only after verifying parent exists.","Replace visibility control with setVisible(false) instead of add/remove churn.","Check for double-removal paths in event handlers."],"exampleFix":"// before\nsubmitButton.remove();\n// after\nif (submitButton.getParent() != null) {\n    submitButton.remove();\n}","handlingStrategy":"type-guard","validationCode":"if (component.getParent() == null) { log.warn(\"skip remove; not attached\"); return; }","typeGuard":"boolean canRemove(Component c) { return c.getParent() != null; }","tryCatchPattern":"try { component.remove(); } catch (IllegalStateException e) { log.warn(\"component already detached\", e); }","preventionTips":["Prefer setVisible(false) over add/remove cycles","Track component attachment state in your own flags","Beware double-remove in event handlers"],"tags":["wicket","component-tree","lifecycle"],"backgroundTag":"invalid-state-transition","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"}