{"record":{"id":"18a3b31a15808077","repo":"theonedev/onedev","slug":"wicket-session-object-not-available","errorCode":null,"errorMessage":"Wicket Session object not available","messagePattern":"Wicket Session object not available","errorType":"exception","errorClass":"WicketRuntimeException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/org/apache/wicket/Component.java","lineNumber":1943,"sourceCode":"\t */\n\tpublic final String getString(final String key, final IModel<?> model, final String defaultValue)\n\t{\n\t\treturn getLocalizer().getString(key, this, model, defaultValue);\n\t}\n\n\t/**\n\t * A convenience method to access the Sessions's style.\n\t * \n\t * @return The style of this component respectively the style of the Session.\n\t * \n\t * @see org.apache.wicket.Session#getStyle()\n\t */\n\tpublic final String getStyle()\n\t{\n\t\tSession session = getSession();\n\t\tif (session == null)\n\t\t{\n\t\t\tthrow new WicketRuntimeException(\"Wicket Session object not available\");\n\t\t}\n\t\treturn session.getStyle();\n\t}\n\n\t/**\n\t * Gets the variation string of this component that will be used to look up markup for this\n\t * component. Subclasses can override this method to define by an instance what markup variation\n\t * should be picked up. By default it will return null or the value of a parent.\n\t * \n\t * @return The variation of this component.\n\t */\n\tpublic String getVariation()\n\t{\n\t\tif (parent != null)\n\t\t{\n\t\t\treturn parent.getVariation();\n\t\t}\n\t\treturn null;","sourceCodeStart":1925,"sourceCodeEnd":1961,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/apache/wicket/Component.java#L1925-L1961","documentation":"Wicket throws this WicketRuntimeException when code on a Component calls getSession() and no Session object is bound to the current thread/request context. Wicket components require an active RequestCycle with a bound Session to resolve things like style, locale, and page state. Calling component APIs outside the request processing thread (or after the session expired) leaves no session available.","triggerScenarios":"Calling component methods that touch Session (e.g. getStyle(), getString(), getSession()-dependent logic) from a background/worker thread, a custom thread pool, a scheduled job, or a deserialization/initialization path outside a Wicket request cycle; also accessing a detached component after the session expired.","commonSituations":"Running Wicket logic in executor threads spawned by an IJob or daemon service; unit tests constructing components without a WebApplication/tester session; accessing components stored statically; calling getStyle() during Application init before any request exists.","solutions":["Run the component code inside the Wicket request thread (request cycle) where a Session is bound.","If work must happen off-thread, capture needed values (locale, style) on the request thread first, or use a Session-bound approach like running code via the page's scheduler.","In tests, use WicketTester which establishes a session; don't instantiate components directly.","Check that the session hasn't expired (session timeout) before touching components.","Refactor to not depend on Session for background logic — pass explicit parameters instead."],"exampleFix":"// before\nexecutor.submit(() -> {\n    label.setDefaultModelObject(loadData()); // touches getSession()\n});\n// after\nexecutor.submit(() -> {\n    Object data = loadData(sessionLocale, sessionStyle); // captured on request thread\n    target.getPage(); // update via AjaxRequestTarget on request thread\n});","handlingStrategy":"try-catch","validationCode":"if (RequestCycle.get() == null || Session.exists() == false) { throw new IllegalStateException(\"No Wicket session on this thread\"); }","typeGuard":"function hasWicketSession() { return org.apache.wicket.Session.exists(); }","tryCatchPattern":"try { component.getStyle(); } catch (WicketRuntimeException e) { log.warn(\"No session bound; skipping style-dependent logic\"); }","preventionTips":["Never call component APIs from non-request threads","Use WicketTester in unit tests to establish a session","Capture session-derived values (locale/style) early and pass them explicitly"],"tags":["wicket","session","lifecycle","threading"],"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-14T05:17:10.506Z"}