{"record":{"id":"77ae2885f00b59e9","repo":"apache/pulsar","slug":"illegal-syntax-uri","errorCode":null,"errorMessage":"Illegal syntax: <uri>","messagePattern":"Illegal syntax: <uri>","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/util/URIPreconditions.java","lineNumber":92,"sourceCode":"    }\n\n    /**\n     * Check whether the given string is a legal URI and passes the user's check.\n     *\n     * @param uri          URI String\n     * @param predicate    User defined rule\n     * @param errorMessage Error message\n     * @throws IllegalArgumentException Illegal URI or failed in the user's rules\n     */\n    public static void checkURI(@NonNull String uri,\n                                @NonNull Predicate<URI> predicate,\n                                @Nullable String errorMessage) throws IllegalArgumentException {\n        requireNonNull(uri, \"uri\");\n        requireNonNull(predicate, \"predicate\");\n        try {\n            URI u = new URI(uri);\n            if (!predicate.test(u)) {\n                throw new IllegalArgumentException(errorMessage == null ? \"Illegal syntax: \" + uri : errorMessage);\n            }\n        } catch (URISyntaxException e) {\n            throw new IllegalArgumentException(errorMessage == null ? \"Illegal syntax: \" + uri : errorMessage);\n        }\n    }\n}\n","sourceCodeStart":74,"sourceCodeEnd":99,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/util/URIPreconditions.java#L74-L99","documentation":"URIPreconditions.checkURI validates a URI string against a caller-supplied predicate and throws IllegalArgumentException when the URI either cannot be parsed by java.net.URI (URISyntaxException) or fails the predicate test. Unless a custom errorMessage is provided, the message is \"Illegal syntax: <uri>\", so the offending string is echoed back to help you spot the malformed part. This is a fail-fast precondition, not a parser: the library assumes callers pass well-formed, predicate-satisfying URIs.","triggerScenarios":"Calling URIPreconditions.checkURI(uri, predicate) where (a) the string is not parseable by new java.net.URI(String) — e.g. spaces, unmatched brackets in a host like http://[::1, illegal characters — or (b) the string parses but fails the supplied predicate (e.g. requiring an absolute/hierarchical URI). The same applies via checkURIIfPresent when a non-null value is passed.","commonSituations":"Broker/ServiceUrl or webServiceUrl config values containing unencoded spaces or copied with surrounding whitespace/quotes; IPv6 literals with a typo (http://[fe80::1); URIs built by string concatenation without URL-encoding; a caller tightening the predicate (e.g. require absolute URIs) while passing relative ones after a version upgrade.","solutions":["Print and inspect the exact string in the message; look for spaces, newlines, quotes, or unencoded characters and remove/encode them.","Fix IPv6 literals to a full bracketed form, e.g. http://[::1]:8080 instead of http://[::1.","Validate with new java.net.URI(uri) in isolation to see the precise URISyntaxException index/message.","If the string parses but fails the predicate, either fix the URI to satisfy it or pass an explicit errorMessage parameter that states the actual requirement.","If the input is user/config supplied, trim and normalize (e.g. strip surrounding quotes) before calling checkURI."],"exampleFix":"// before\nString url = \"pulsar://localhost :6650\"; // embedded space\nURIPreconditions.checkURI(url, u -> u.getScheme() != null);\n\n// after\nString url = \"pulsar://localhost:6650\";\nURIPreconditions.checkURI(url, u -> u.getScheme() != null, \"Service URL must have a scheme\");","handlingStrategy":"validation","validationCode":"static void validateUri(String uri) {\n    if (uri == null || uri.isBlank()) throw new IllegalArgumentException(\"uri is null/blank\");\n    try {\n        java.net.URI u = new java.net.URI(uri.trim());\n        if (u.getScheme() == null) throw new IllegalArgumentException(\"uri has no scheme: \" + uri);\n    } catch (java.net.URISyntaxException e) {\n        throw new IllegalArgumentException(\"Bad URI at index \" + e.getIndex() + \": \" + e.getReason(), e);\n    }\n}","typeGuard":"static boolean isParseableUri(String s) {\n    if (s == null) return false;\n    try { new java.net.URI(s); return true; } catch (java.net.URISyntaxException e) { return false; }\n}","tryCatchPattern":"try {\n    URIPreconditions.checkURI(uri, predicate);\n} catch (IllegalArgumentException e) {\n    log.error(\"Rejected URI '{}': {}\", uri, e.getMessage());\n    throw new ConfigException(\"Invalid URI configured: \" + uri, e);\n}","preventionTips":["Trim and strip quotes from config/environment-sourced URI values before validating.","Prefer building URIs with the multi-argument java.net.URI constructor so components are encoded automatically.","Run ./pulsar or your app with a startup config validation step that calls checkURI early, so bad config fails at boot.","Supply a descriptive errorMessage to checkURI so failures state the actual constraint."],"tags":["java","uri","input-validation"],"backgroundTag":"invalid-uri-syntax","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}