{"record":{"id":"aff4ea367f8bd423","repo":"flowable/flowable-engine","slug":"invalid-url-exception-occurred-aff4ea","errorCode":null,"errorMessage":"Invalid URL exception occurred","messagePattern":"Invalid URL exception occurred","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-http-common/src/main/java/org/flowable/http/common/impl/apache/client5/ApacheHttpComponents5FlowableHttpClient.java","lineNumber":232,"sourceCode":"                case \"HEAD\": {\n                    request = AsyncRequestBuilder.head(uri);\n                    break;\n                }\n                case \"OPTIONS\": {\n                    request = AsyncRequestBuilder.options(uri);\n                    break;\n                }\n                default: {\n                    throw new FlowableException(requestInfo.getMethod() + \" HTTP method not supported\");\n                }\n            }\n\n            setHeaders(request, requestInfo.getHttpHeaders());\n            setHeaders(request, requestInfo.getSecureHttpHeaders());\n\n            return new ApacheHttpComponentsExecutableHttpRequest(request.build(), createRequestConfig(requestInfo));\n        } catch (URISyntaxException ex) {\n            throw new FlowableException(\"Invalid URL exception occurred\", ex);\n        } catch (IOException ex) {\n            throw new FlowableException(\"IO exception occurred\", ex);\n        }\n    }\n\n    protected URI createUri(String url) throws URISyntaxException {\n        String uri = SPACE_CHARACTER_PATTERN.matcher(url).replaceAll(ENCODED_SPACE_CHARACTER);\n        return new URI(PLUS_CHARACTER_PATTERN.matcher(uri).replaceAll(ENCODED_PLUS_CHARACTER));\n    }\n\n    protected void setRequestEntity(HttpRequest requestInfo, AsyncRequestBuilder requestBase) throws UnsupportedEncodingException {\n        if (requestInfo.getBody() != null) {\n            if (StringUtils.isNotEmpty(requestInfo.getBodyEncoding())) {\n                requestBase.setEntity(AsyncEntityProducers.create(requestInfo.getBody(), Charset.forName(requestInfo.getBodyEncoding())));\n            } else {\n                requestBase.setEntity(AsyncEntityProducers.create(requestInfo.getBody()));\n            }\n        } else if (requestInfo.getBodyBytes() != null) {","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-http-common/src/main/java/org/flowable/http/common/impl/apache/client5/ApacheHttpComponents5FlowableHttpClient.java#L214-L250","documentation":"`prepareRequest` in the HttpClient 5.x client converts the configured URL into a `java.net.URI` (via `createUri`, which pre-encodes spaces and pluses). A `URISyntaxException` from that conversion is wrapped as `FlowableException(\"Invalid URL exception occurred\", cause)` — the URL string is not a syntactically valid URI.","triggerScenarios":"Calling `prepareRequest()` with a `requestInfo` URL containing illegal URI characters (raw spaces beyond the pre-encoded ones, unencoded `|`, `{`, `}`, `<`, `>`, quotes, or a malformed scheme like \"htp://\").","commonSituations":"Building URLs by string concatenation with unencoded query values (unescaped special characters); config values with stray whitespace/newlines; template variables expanded to values containing reserved characters.","solutions":["URL-encode dynamic path/query segments before inserting them (e.g. `URLEncoder.encode(value, StandardCharsets.UTF_8)`).","Validate the final URL: `new URI(url)` in a pre-check, or run the request through `createUri`'s encoding first.","Fix the scheme/host typos in the HTTP task configuration.","Log the exact URL from `requestInfo` — the wrapped cause's message shows the offending character and index."],"exampleFix":"// before\nString url = baseUrl + \"/search?q=\" + query;\n\n// after\nString url = baseUrl + \"/search?q=\" + URLEncoder.encode(query, StandardCharsets.UTF_8);","handlingStrategy":"validation","validationCode":"boolean isValidUrl(String url) {\n    try {\n        URI uri = new URI(url.replace(\" \", \"%20\"));\n        return uri.getScheme() != null && uri.getHost() != null;\n    } catch (URISyntaxException e) {\n        return false;\n    }\n}\n// call before invoking the client; encode query values with URLEncoder first","typeGuard":null,"tryCatchPattern":"try {\n    return client.call(requestInfo);\n} catch (FlowableException e) {\n    if (\"Invalid URL exception occurred\".equals(e.getMessage())) {\n        log.error(\"URL '{}' is not a valid URI: {}\", requestInfo.getUrl(), e.getCause());\n    }\n    throw e;\n}","preventionTips":["Always URLEncoder.encode dynamic path and query segments.","Never concatenate raw user/process-variable values into URLs.","Validate URLs at configuration time, not request time."],"tags":["url","uri","encoding","validation"],"backgroundTag":"invalid-url-format","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}