theonedev/onedev · error · org.apache.wicket.WicketRuntimeException

An error occurred while generating an Url for handler '%s'

Error message

An error occurred while generating an Url for handler '%s'

What it means

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.

Source

Thrown at server-core/src/main/java/org/apache/wicket/request/cycle/RequestCycle.java:556

	 * Returns the rendered URL for the request handler or <code>null</code> if the handler couldn't
	 * have been rendered.
	 * <p>
	 * The resulting URL will be relative to current page.
	 * 
	 * @param handler
	 * @return Url String or <code>null</code>
	 */
	public CharSequence urlFor(IRequestHandler handler)
	{
		try
		{
			Url mappedUrl = mapUrlFor(handler);
			CharSequence url = renderUrl(mappedUrl, handler);
			return url;
		}
		catch (Exception x)
		{
			throw new WicketRuntimeException(String.format(
				"An error occurred while generating an Url for handler '%s'", handler), x);
		}

	}

	private String renderUrl(Url url, IRequestHandler handler)
	{
		if (url != null)
		{
			boolean shouldEncodeStaticResource = Application.exists() &&
				Application.get().getResourceSettings().isEncodeJSessionId();

			String renderedUrl = getUrlRenderer().renderUrl(url);
			if (handler instanceof ResourceReferenceRequestHandler)
			{
				ResourceReferenceRequestHandler rrrh = (ResourceReferenceRequestHandler)handler;
				IResource resource = rrrh.getResource();
				if (resource != null && !(resource instanceof IStaticCacheableResource) ||

View on GitHub (pinned to d44925c47c)

Solutions

  1. Inspect the cause (getCause()) of the WicketRuntimeException — it names the underlying mapper/encoding failure
  2. Verify the target page/handler class is mounted or has a mapper that accepts its parameters
  3. Check for exceptions thrown in the page's constructor or IMapperContext during URL building
  4. Log the handler's toString() (included in the message) to see which handler is unresolvable

Example fix

// before
Url url = requestCycle.mapUrlFor(handler); // or urlFor on a broken mapper
// after
// ensure the page is mounted in Application.init():
mountPage("/details", DetailsPage.class);
CharSequence url = requestCycle.urlFor(DetailsPage.class, params);
Defensive patterns

Strategy: try-catch

Validate before calling

// Java
boolean mountable = requestCycle.getRequest().getParameters() != null
        && application.getRootRequestMapper().mapHandler(handler) != null; // verify mapper resolution in a dry run if feasible

Try / catch

try {
    CharSequence url = requestCycle.urlFor(handler);
} catch (WicketRuntimeException e) {
    log.error("URL generation failed for handler " + handler, e.getCause());
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/f14447fca8280b21. Report an issue: GitHub.