apereo/cas · warning
Unable to encode URL
Error message
Unable to encode URL %s
What it means
HttpMessage.formatOutputMessageInternal URL-encodes the message with UTF-8. Any exception during encoding is caught, this warning is logged, and the original unencoded message is returned as a fallback. Because URLEncoder.encode with a fixed charset practically never throws, this warning usually indicates a genuinely unexpected problem; the observable effect is a message that is not URL-encoded in the output.
Solutions
- Check the stack trace logged with this warning to see the underlying exception (most likely NPE from a null message).
- Ensure callers never construct HttpMessage with a null message string.
- Verify the JVM's charset providers are intact (a broken java.nio.charset setup can make URLEncoder throw).
- If the fallback raw message breaks downstream URL handling, sanitize the message before constructing HttpMessage.
Example fix
// before HttpMessage msg = new HttpMessage(null); // after HttpMessage msg = new HttpMessage(StringUtils.defaultString(rawValue));
Defensive patterns
Strategy: try-catch
Validate before calling
if (rawMessage == null) {
throw new IllegalArgumentException("HttpMessage requires a non-null message");
} Try / catch
try {
String encoded = URLEncoder.encode(message, StandardCharsets.UTF_8);
} catch (Exception e) {
LOGGER.warn("Unable to encode URL", e);
// fall back to raw message and check the logged cause
} Prevention
- Never pass null into HttpMessage.
- Sanitize message content before constructing HttpMessage.
- Keep JVM charset providers intact; verify UTF-8 default charset.
When it happens
Trigger: URLEncoder.encode(message, StandardCharsets.UTF_8) throws while producing an HttpMessage output (e.g. the message constructor argument is null or in a corrupted state), during getMessage()/formatOutputMessage calls used in webflow output messages.
Common situations: Passing a null message into HttpMessage; downstream framework changes altering charset handling; extremely unusual runtime state (SecurityException on charset provider) in restricted JVMs.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- Failed to load configuration metadata
- Unable to accept response status
- <policy status exception>
- State [ : : ] does not have a matching transition for
- No credentials can be extracted to authenticate the REST…
AI-assisted analysis of apereo/cas@e7288fc434 (2026-09-08).
Data as JSON: /api/errors/55119f9a2fe2545a.
Report an issue: GitHub.
Appendix: source
Thrown at api/cas-server-core-api-web/src/main/java/org/apereo/cas/web/HttpMessage.java:70
@Builder.Default
private String contentType = MediaType.APPLICATION_FORM_URLENCODED_VALUE;
public HttpMessage(final URL url, final String message) {
this(url, message, DEFAULT_ASYNCHRONOUS_CALLBACKS_ENABLED);
}
/**
* Encodes the message in UTF-8 format in preparation to send.
*
* @param message Message to format and encode
* @return The encoded message.
*/
protected String formatOutputMessageInternal(final String message) {
try {
return URLEncoder.encode(message, StandardCharsets.UTF_8);
} catch (final Exception e) {
val msg = String.format("Unable to encode URL %s", message);
LOGGER.warn(msg, e);
}
return message;
}
public String getMessage() {
return formatOutputMessageInternal(this.message);
}
}
View on GitHub (pinned to e7288fc434)