theonedev/onedev · error · WicketRuntimeException
An error occurred while detaching component:
Error message
An error occurred while detaching component:
What it means
Component.detach() wraps the detach phase (onDetach, model detach, behavior detach) in a try/catch and rethrows any Exception as a WicketRuntimeException with the message 'An error occurred while detaching component: ' plus the component's toString. The original exception is attached as the cause, so this is a wrapper around any failure in user detach code.
Source
Thrown at server-core/src/main/java/org/apache/wicket/Component.java:1195
if (getFlag(FLAG_DETACHING))
{
throw new IllegalStateException(Component.class.getName() +
" has not been properly detached. Something in the hierarchy of " +
getClass().getName() +
" has not called super.onDetach() in the override of onDetach() method");
}
// always detach models because they can be attached without the
// component. eg component has a compoundpropertymodel and one of its
// children component's getmodelobject is called
detachModels();
// detach any behaviors
new Behaviors(this).detach();
}
catch (Exception x)
{
throw new WicketRuntimeException("An error occurred while detaching component: " + toString(true), x);
}
// always detach children because components can be attached
// independently of their parents
detachChildren();
// reset the model to null when the current model is a IWrapModel and
// the model that created it/wrapped in it is a IComponentInheritedModel
// The model will be created next time.
if (getFlag(FLAG_INHERITABLE_MODEL))
{
setModelImpl(null);
setFlag(FLAG_INHERITABLE_MODEL, false);
}
clearEnabledInHierarchyCache();
clearVisibleInHierarchyCache();
View on GitHub (pinned to d44925c47c)
Solutions
- Read the 'Caused by' exception to find the real failure
- Fix the underlying exception in the component's onDetach/load/model code
- Null-check resources in detach logic; avoid touching closed sessions
- Wrap risky detach work in try/finally with super.onDetach() still called
Example fix
// before
@Override
protected void onDetach() {
getSession().bind(); // may fail after session invalidation
super.onDetach();
}
// after
@Override
protected void onDetach() {
try {
if (getSession() != null) {
getSession().bind();
}
} finally {
super.onDetach();
}
} Defensive patterns
Strategy: try-catch
Validate before calling
// nothing to validate up front; ensure detach logic is null-safe:
if (model != null && model.getObject() != null) { /* safe to touch */ } Try / catch
try {
component.detach();
} catch (WicketRuntimeException e) {
Throwable cause = e.getCause(); // inspect the real failure
log.error("detach failed for component", cause);
} Prevention
- Always read the 'Caused by' chain — this error is only a wrapper
- Make onDetach and lazy model load() null-safe and session-independent
- Avoid database/network access in detach paths
When it happens
Trigger: Any Exception thrown during detach: e.g. a LazyLoadableDetachableModel's load() throwing, a custom onDetach()/onModelChanged throwing, or behavior detach failing.
Common situations: Database/session resources accessed during detach after the underlying session closed; NPEs in custom detach logic; load failures in lazy models at end of request.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Cannot determine Markup. Component is not yet connected to a
- has not been properly initialized. Something in the hierarc
- has not been properly added. Something in the hierarchy of
- has not been properly detached. Something in the hierarchy
- has not been properly rendered. Something in the hierarchy
AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06).
Data as JSON: /api/errors/6d3913b47c2f73d8.
Report an issue: GitHub.