{"record":{"id":"f14447fca8280b21","repo":"theonedev/onedev","slug":"an-error-occurred-while-generating-an-url-for-hand","errorCode":null,"errorMessage":"An error occurred while generating an Url for handler '%s'","messagePattern":"An error occurred while generating an Url for handler '(.+?)'","errorType":"exception","errorClass":"org.apache.wicket.WicketRuntimeException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/org/apache/wicket/request/cycle/RequestCycle.java","lineNumber":556,"sourceCode":"\t * Returns the rendered URL for the request handler or <code>null</code> if the handler couldn't\n\t * have been rendered.\n\t * <p>\n\t * The resulting URL will be relative to current page.\n\t * \n\t * @param handler\n\t * @return Url String or <code>null</code>\n\t */\n\tpublic CharSequence urlFor(IRequestHandler handler)\n\t{\n\t\ttry\n\t\t{\n\t\t\tUrl mappedUrl = mapUrlFor(handler);\n\t\t\tCharSequence url = renderUrl(mappedUrl, handler);\n\t\t\treturn url;\n\t\t}\n\t\tcatch (Exception x)\n\t\t{\n\t\t\tthrow new WicketRuntimeException(String.format(\n\t\t\t\t\"An error occurred while generating an Url for handler '%s'\", handler), x);\n\t\t}\n\n\t}\n\n\tprivate String renderUrl(Url url, IRequestHandler handler)\n\t{\n\t\tif (url != null)\n\t\t{\n\t\t\tboolean shouldEncodeStaticResource = Application.exists() &&\n\t\t\t\tApplication.get().getResourceSettings().isEncodeJSessionId();\n\n\t\t\tString renderedUrl = getUrlRenderer().renderUrl(url);\n\t\t\tif (handler instanceof ResourceReferenceRequestHandler)\n\t\t\t{\n\t\t\t\tResourceReferenceRequestHandler rrrh = (ResourceReferenceRequestHandler)handler;\n\t\t\t\tIResource resource = rrrh.getResource();\n\t\t\t\tif (resource != null && !(resource instanceof IStaticCacheableResource) ||","sourceCodeStart":538,"sourceCodeEnd":574,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/apache/wicket/request/cycle/RequestCycle.java#L538-L574","documentation":"RequestCycle.urlFor(IRequestHandler) maps a request handler to a URL; if any step (mapping, encoding, rendering) throws, Wicket wraps the original exception in a WicketRuntimeException with the message 'An error occurred while generating an Url for handler %s'. The real cause is in the chained exception, which usually points to a failing IRequestMapper, encoding scheme, or handler state.","triggerScenarios":"Calling requestCycle.urlFor(handler) or link/BookmarkablePageLink URL generation when the handler cannot be mapped (no matching mapper, invalid page parameters, thrown exception inside a mapper's mapHandler/getUrl).","commonSituations":"Mounting changes that removed the mapper for a page class; malformed PageParameters that fail URL encoding; custom IRequestMappers throwing; page class constructor throwing during URL creation.","solutions":["Inspect the cause (getCause()) of the WicketRuntimeException — it names the underlying mapper/encoding failure","Verify the target page/handler class is mounted or has a mapper that accepts its parameters","Check for exceptions thrown in the page's constructor or IMapperContext during URL building","Log the handler's toString() (included in the message) to see which handler is unresolvable"],"exampleFix":"// before\nUrl url = requestCycle.mapUrlFor(handler); // or urlFor on a broken mapper\n// after\n// ensure the page is mounted in Application.init():\nmountPage(\"/details\", DetailsPage.class);\nCharSequence url = requestCycle.urlFor(DetailsPage.class, params);","handlingStrategy":"try-catch","validationCode":"// Java\nboolean mountable = requestCycle.getRequest().getParameters() != null\n        && application.getRootRequestMapper().mapHandler(handler) != null; // verify mapper resolution in a dry run if feasible","typeGuard":null,"tryCatchPattern":"try {\n    CharSequence url = requestCycle.urlFor(handler);\n} catch (WicketRuntimeException e) {\n    log.error(\"URL generation failed for handler \" + handler, e.getCause());\n}","preventionTips":["Always inspect getCause() — the wrapper message hides the real failure","Keep page constructors exception-free so URL building cannot fail","Re-check mount registrations after refactoring mappers","Log handler.toString() when reporting the issue"],"tags":["wicket","url-mapping","runtime-exception"],"backgroundTag":"invalid-url","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"}