{"record":{"id":"55119f9a2fe2545a","repo":"apereo/cas","slug":"unable-to-encode-url-s","errorCode":null,"errorMessage":"Unable to encode URL %s","messagePattern":"Unable to encode URL (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"api/cas-server-core-api-web/src/main/java/org/apereo/cas/web/HttpMessage.java","lineNumber":70,"sourceCode":"    @Builder.Default\n    private String contentType = MediaType.APPLICATION_FORM_URLENCODED_VALUE;\n    \n    public HttpMessage(final URL url, final String message) {\n        this(url, message, DEFAULT_ASYNCHRONOUS_CALLBACKS_ENABLED);\n    }\n\n    /**\n     * Encodes the message in UTF-8 format in preparation to send.\n     *\n     * @param message Message to format and encode\n     * @return The encoded message.\n     */\n    protected String formatOutputMessageInternal(final String message) {\n        try {\n            return URLEncoder.encode(message, StandardCharsets.UTF_8);\n        } catch (final Exception e) {\n            val msg = String.format(\"Unable to encode URL %s\", message);\n            LOGGER.warn(msg, e);\n        }\n        return message;\n    }\n\n    public String getMessage() {\n        return formatOutputMessageInternal(this.message);\n    }\n}\n","sourceCodeStart":52,"sourceCodeEnd":79,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/api/cas-server-core-api-web/src/main/java/org/apereo/cas/web/HttpMessage.java#L52-L79","documentation":"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.","triggerScenarios":"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.","commonSituations":"Passing a null message into HttpMessage; downstream framework changes altering charset handling; extremely unusual runtime state (SecurityException on charset provider) in restricted JVMs.","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."],"exampleFix":"// before\nHttpMessage msg = new HttpMessage(null);\n\n// after\nHttpMessage msg = new HttpMessage(StringUtils.defaultString(rawValue));","handlingStrategy":"try-catch","validationCode":"if (rawMessage == null) {\n    throw new IllegalArgumentException(\"HttpMessage requires a non-null message\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    String encoded = URLEncoder.encode(message, StandardCharsets.UTF_8);\n} catch (Exception e) {\n    LOGGER.warn(\"Unable to encode URL\", e);\n    // fall back to raw message and check the logged cause\n}","preventionTips":["Never pass null into HttpMessage.","Sanitize message content before constructing HttpMessage.","Keep JVM charset providers intact; verify UTF-8 default charset."],"tags":["url-encoding","webflow","http","charset"],"backgroundTag":"invalid-url-format","analyzedSha":"e7288fc434b4f4505b8452e1a57e8fb3111bb863","analyzedAt":"2026-09-08T15:39:16.015Z","contentChangedAt":"2026-09-08T15:39:16.015Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}