{"record":{"id":"539f343f67bc6ba9","repo":"elastic/elasticsearch","slug":"unable-to-parse-uri-uristring","errorCode":null,"errorMessage":"unable to parse URI [${uriString}]","messagePattern":"unable to parse URI \\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/web-utils/src/main/java/org/elasticsearch/web/UriParts.java","lineNumber":75,"sourceCode":"\n    public static Map<String, Object> parse(String uriString) {\n        final var uriParts = new UriPartsMapCollector();\n        parse(uriString, uriParts);\n        return uriParts;\n    }\n\n    @SuppressForbidden(reason = \"URL.getPath is used only if URI.getPath is unavailable\")\n    public static void parse(final String uriString, final UriPartsCollector uriPartsCollector) {\n        URI uri = null;\n        URL fallbackUrl = null;\n        try {\n            uri = new URI(uriString);\n        } catch (URISyntaxException e) {\n            try {\n                // noinspection deprecation\n                fallbackUrl = new URL(uriString);\n            } catch (MalformedURLException e2) {\n                throw new IllegalArgumentException(\"unable to parse URI [\" + uriString + \"]\");\n            }\n        }\n\n        String domain;\n        String fragment;\n        String path;\n        int port;\n        String query;\n        String scheme;\n        String userInfo;\n\n        if (uri != null) {\n            domain = uri.getHost();\n            fragment = uri.getFragment();\n            path = uri.getPath();\n            port = uri.getPort();\n            query = uri.getQuery();\n            scheme = uri.getScheme();","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/web-utils/src/main/java/org/elasticsearch/web/UriParts.java#L57-L93","documentation":"UriParts.parse first attempts new URI(uriString); if that throws URISyntaxException it falls back to new URL(uriString). Only if both fail does it raise IllegalArgumentException. So the input must be malformed for both the strict URI parser and the lenient URL parser (no valid scheme/host).","triggerScenarios":"Calling UriParts.parse(uriString, collector) with a string that is neither a valid URI nor a valid URL - typically missing scheme, illegal characters, or empty. Used by the URL-decomposition ingest processor path.","commonSituations":"A user-supplied URL missing the scheme (example.com/path instead of https://example.com/path); control characters or spaces in the URL; a field that occasionally contains non-URL text (user agents, referrer noise); pipeline processing of malformed logs.","solutions":["Prepend a default scheme when missing: if (!uri.matches(\"^[a-zA-Z]+:.*\")) uri = \"https://\" + uri","Validate with a regex or pre-parse before calling UriParts.parse","Filter blank/non-URL rows in the ingest pipeline before this processor"],"exampleFix":"// before\nUriParts.parse(\"example.com/path\", collector); // throws\n// after\nString s = raw;\nif (!s.matches(\"^[a-zA-Z][a-zA-Z0-9+.-]*:.*\")) s = \"https://\" + s;\nUriParts.parse(s, collector);","handlingStrategy":"validation","validationCode":"String s = raw == null ? \"\" : raw.trim();\nif (!s.matches(\"^[a-zA-Z][a-zA-Z0-9+.-]*:.*\")) {\n    s = \"https://\" + s;\n}\ntry {\n    UriParts.parse(s, collector);\n} catch (IllegalArgumentException e) {\n    // drop or mark the row as unparseable\n}","typeGuard":"static boolean looksLikeUri(String s) {\n    if (s == null || s.isBlank()) return false;\n    try { new URI(s); return true; }\n    catch (URISyntaxException e1) {\n        try { new URL(s); return true; }\n        catch (MalformedURLException e2) { return false; }\n    }\n}","tryCatchPattern":"try { UriParts.parse(uri, collector); }\ncatch (IllegalArgumentException e) { /* route to dead-letter / skip */ }","preventionTips":["Normalise scheme before parsing in pipelines","Drop blank fields before this processor","Use a regex prefilter for very noisy inputs"],"tags":["web-utils","uri","parsing","ingest"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}